Hi Brian,
Is there a mandatory block size for the data you want to encrypt? Like N times 16 bytes or so?
Another thought: are the fields like Token and Input defined as variable length? With %addr() you would then be passing a pointer to the 'length section' of such a field. As you (also) need to pass the length as a separate parameter, including the length of a variable field may not to be the right thing to do.
Kind regards,
Martijn van Breden
lead software architect
-----Oorspronkelijk bericht-----
Van: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> Namens Brian Garland via RPG400-L
Verzonden: donderdag 9 februari 2023 15:13
Aan: rpg400-l@xxxxxxxxxxxxxxxxxx
CC: Brian Garland <Brian.Garland@xxxxxxxxxx>
Onderwerp: Re: Qc3VerifySignature to verify a JWT
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
I did find one translation issue and am now getting CPF9DCE "A data length is not valid". This is a pretty vague message.
Given the data I'm passing I think I am passing the correct lengths. This makes me think I may be passing some wrong data so the error means "not expected" more than "wrong for the data passed" so I need to verify some assumptions I made about the parameters.
If you see anything that I'm doing wrong please let me know.
Parm 1 - Signature - The actual JWT
Parm 2 - Length of parm 1
Parm 3 - Input Data - The decoded header and payload from the JWT Parm 4 - Length of parm 3 Parm 5 - 'DATA0100'
Parm 6 - ALGD0400 structure
DCL-DS ALGD0400;
Algorithm INT(10) INZ(50);
BlockFormat CHAR(1) INZ('1');
Reserved CHAR(3) INZ(*LOVAL);
SigningAlgo INT(10) INZ(3);
END-DS;
Parm 7 - 'ALGD0400'
Parm 8 - KEYD0600 structure
DCL-DS KEYD0600;
PEMLength INT(10) INZ(0);
PEMReserved CHAR(4) INZ(*LOVAL);
PEMCertificate CHAR(8000) CCSID(*HEX); END-DS; Parm 9 - 'KEYD0600'
Parm 10 - '1'
Parm 11 - ' '
Parm 12 - standard error DS
Prototype:
DCL-PR VerifySignature EXTPROC('Qc3VerifySignature');
Signature POINTER VALUE;
SignatureLen INT(10) CONST;
InputData POINTER VALUE;
InputDataLen INT(10) CONST;
InputDataFormat CHAR(8) CONST;
AlgorithmDesc POINTER VALUE;
AlgorithmDescFormat CHAR(8) CONST;
KeyDesc POINTER VALUE;
KeyDescFormat CHAR(8) CONST;
CryptoProvider CHAR(1) CONST;
CrpytoDevice CHAR(10) CONST;
APIError POINTER VALUE;
END-PR;
Call:
VerifySignature(%ADDR(Token):TokenLen:
%ADDR(Input):InputLen:'DATA0100':
%ADDR(ALGD0400):'ALGD0400':
%ADDR(KEYD0600):'KEYD0600':
'1':' ':%ADDR(apierror));
For testing, the JWT and public certificate are stored in regular RPGLE CHAR variables. I'm able to decode the JWT to get the header and payload in order to create the string for the input data parm (header + '.' + payload). I put the JWT and the input data into *UTF8 variables before passing them to the API.
PEMCertificate (in KEYD0600) is set to the text of the PEM formatted certificate which for this test is set in an RPG string and then translated to ASCII using QDCXLATE.
certificate = '-----BEGIN CERTIFICATE-----' + x'25' + etc.
Brian
--
This email and any files transmitted with it are confidential and intended solely for the use of the individual or company to whom they are addressed.
Do not disclose, distribute, or copy this email to others outside your company. If you have received this email in error, please notify the sender immediately and delete this email from your system.
--
This is the RPG programming on IBM i (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.
As an Amazon Associate we earn from qualifying purchases.