question

WendyNi-5960 avatar image
0 Votes"
WendyNi-5960 asked XiaopoYang-MSFT answered

COPP: Importing the Drivers Public Key cause program exception; Initiating a COPP Session Fail,NTE_BAD_LEN from CryptEncrypt()

I'm trying to use this API and I go through the keyexchange,validate certs,get driver public key & random number, encode the AMCoppSignature。
First:
when i want to "Importing the Drivers Public Key" following the sample COde, CryptImportKey() will cause program exception。 The pointer pkey should point to the position after rsapubkey, but in the current writing, the position pkey points to shifts by 132 bytes
Because the prspubkkey type is rsapubkey*。


 // The next block of data is the RSAPUBKEY structure.
 RSAPUBKEY *pRsaPubKey = (RSAPUBKEY*)(pBlob + sizeof(PUBLICKEYSTRUC));
 pRsaPubKey->magic = RSA1;            // Public key.
 pRsaPubKey->bitlen = cbModulus * 8;  // Number of bits in the modulus.
 pRsaPubKey->pubexp = dwExponent;     // Exponent.
    
 // Copy the modulus into the blob. Put the modulus directly after the
 // RSAPUBKEY structure in the blob.
 BYTE *pKey = (BYTE*)(pRsaPubkey + sizeof(RSAPUBKEY));
 CopyMemory(pKey, pModulus, cbModulus);
    
 // Now import the key.
 HCRYPTKEY hRSAKey;  // Receives a handle to the key.
 CryptImportKey(hCSP, pBlob, cbKeyBlob, 0, 0, &hRSAKey) 


Second : According to the sample Code , Initiating a COPP Session Fail,NTE_BAD_LEN from CryptEncrypt().

 AMCOPPSignature CoppSig;
 ZeroMemory(&CoppSig, sizeof(CoppSig));
 // Copy the signature data into CoppSig. (Not shown.)
    
 // Encrypt the signature:
 const DWORD RSA_PADDING = 11;    // 11-byte padding.
 DWORD cbDataOut = sizeof(AMCOPPSignature);
 DWORD cbDataIn = cbDataOut - RSA_PADDING;
 CryptEncrypt(
     hRSAKey, 
     NULL,     // No hash object.
     TRUE,     // Final block to encrypt.
     0,        // Reserved.
     &CoppSig, // COPP signature.
     &cbDataOut, 
     cbDataIn
 );




windows-apic++
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered Viorel-1 edited

For the first problem try this fix:

 BYTE *pKey = ((BYTE*)pRsaPubkey) + sizeof(RSAPUBKEY);
 or
 BYTE *pKey = (BYTE*)(pRsaPubkey + 1);

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

XiaopoYang-MSFT avatar image
0 Votes"
XiaopoYang-MSFT answered

Have you solved the problem? I hear from you that was a bug in your swaping function after base64-decoding.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.