CMP Cert request - permission/support error

TM <[email protected]> Sun, 09 Nov 2014 22:33:41 +0100
Newsgroups gmane.comp.encryption.cryptlib
Message-ID <[email protected]>
Hi

Now I am having -21 error 'Cannot connect session: Server returned error code 4 (bit 2): This transaction is not permitted or supported.
locum 0,
type 0.

Code:

Client.exe

function IssueCertificateRequest(UserKeyPair : TCryptKey):TCryptCert;
var
  resultCode: integer;

begin
    resultCode := 0;

    Result := TCryptCert.Create(CRYPT_CERTTYPE_REQUEST_CERT); //cmp
    Result.AddPublicKey(UserKeyPair); // cryptSetAttribute(Result.Handle, CRYPT_CERTINFO_SUBJECTPUBLICKEYINFO, UserKeyPair.Handle);
    Result.CountryName := countryName;
    Result.ProvinceName := stateName;
    Result.Locality := cityName;
    Result.Organisation := companyName;
    Result.OrganisationalUnit := departmentName;
    Result.CommonName := commonName;
    Result.EMail := emailName;
    Result.SignWith(UserKeyPair);
    Result.Check;

end;


Main:



ResultCode:=0;
//   ResultCode := cryptInit;
    FcryptSession := TCryptSession.Create(CRYPT_SESSION_CMP); // cryptCreateSession(FcryptSession.Handle, CRYPT_UNUSED,
CRYPT_SESSION_CMP);

    FcryptSession.ServerName := ServerName; // CRYPT_SESSINFO_SERVER_NAME
    FcryptSession.ServerPort := ServerPort; // CRYPT_SESSINFO_SERVER_PORT
    FcryptSession.ConnectTimeout := 300;
    FcryptSession.ReadTimeout := 300;
    ResultCode := cryptSetAttribute( FcryptSession.Handle, CRYPT_SESSINFO_CMP_REQUESTTYPE, CRYPT_REQUESTTYPE_INITIALISATION);
    FcryptSession.UserName := PKI.UserID;  // CRYPT_SESSINFO_USERNAME
    FcryptSession.Password := PKI.IssuePass; //CRYPT_SESSINFO_PASSWORD
    FcryptSession.SetAttribute(CRYPT_SESSINFO_CACERTIFICATE, cryptCACert.Handle);

    cryptCmpRequest := IssueCertificateRequest(UserKeyPair);
	
    ResultCode := cryptSetAttribute(FcryptSession.Handle, CRYPT_SESSINFO_REQUEST, cryptCmpRequest.Handle);

    if ResultCode <> 0 then
       begin

         cryptGetAttribute( FcryptSession.Handle, CRYPT_ATTRIBUTE_ERRORLOCUS, &errorLocus );
         cryptGetAttribute( FcryptSession.Handle, CRYPT_ATTRIBUTE_ERRORTYPE, &errorType );

       end;
    FcryptSession.Activate; //err := cryptSetAttribute(FcryptSession.Handle, CRYPT_SESSINFO_ACTIVE, 1);  <----------ERROR
    newCert := FCMPClient.newCertificate; // cryptGetAttribute(session.CryptHandle, CRYPT_SESSINFO_RESPONSE, CryptHandle);
    newCert.Check(cryptCaCert);
    UserPrivateKeySet.AddPublicKey(newCert);	
end;


Server.exe:


var
   resultCode: integer;
   cert: CRYPT_CERTIFICATE;
	pk : CRYPT_CONTEXT ;
begin
         resultCode := 0;
//        Result := True;
         if not Main_Crypt_Inited then resultCode := cryptInit();
         try
           FcryptCertStore := TCryptKeyset.Create(CRYPT_KEYSET_ODBC_STORE, PAnsiChar(caKeystoreName), CRYPT_KEYOPT_NONE);
           FcryptCaKeyset := TCryptKeyset.Create(CRYPT_KEYSET_FILE, PAnsiChar(caKeyPairFilename), CRYPT_KEYOPT_READONLY);
           FprivateKey.GetPrivateKey(FcryptCaKeyset, CRYPT_KEYID_NAME, privateKeyLabel, privateKeyPassword); // resultCode := cryptGetPrivateKey(cryptCaKeyset.Handle, pk , CRYPT_KEYID_NAME, 
PAnsiChar(privateKeyLabel), PAnsiChar(privateKeyPassword));
           resultCode := cryptCACertManagement(cert, CRYPT_CERTACTION_CLEANUP, FcryptCertStore.Handle, CRYPT_UNUSED, CRYPT_UNUSED);
//          	/* Create the session */
           cryptSession := TCryptSession.Create(CRYPT_SESSION_CMP_SERVER);
           cryptSession.ServerPort := ServerPort;
           cryptSession.Keyset := cryptCertStore; // cryptSetAttribute(cryptSession.Handle, CRYPT_SESSINFO_KEYSET, FcryptCertStore.Handle);
           cryptSession.PrivateKey := privateKey; // cryptSetAttribute(cryptSession.Handle, CRYPT_SESSINFO_PRIVATEKEY,  FprivateKey.Handle);
           cryptSession.ConnectTimeout := 60;
           cryptSession.Activate; // cryptSetAttribute(cryptSession.Handle, CRYPT_SESSINFO_ACTIVE, 1 );


         except
           if Assigned(cryptSession) then cryptSession.Free;

           if not Main_Crypt_Inited then resultCode := cryptEnd();
         end;
end;


Debug outputs:
client output

Debug Output:
CLI: Set userID.

Process client.exe (9288)
Debug Output:
CLI    9 13200334 54 B4 2C EE 45 23 84 25 00                      T.,.E#.%.

Process client.exe (9288)
Debug Output:
CLI: Set new transID.

Process client.exe (9288)
Debug Output:
CLI   16 434C0747 77 94 6E 61 E4 32 A0 15 E0 DB 78 07 FB 02 10 5A w.na.2....x....Z

Process client.exe (9288)
Debug Output:
CLI: Writing message body type 1.

Process client.exe (9288)
Debug Output:
CLI: Writing MAC params with salt, 500 iterations.

Process client.exe (9288)
Debug Output:
CLI   16 420E0835 C6 74 38 26 32 03 CB D3 DA B0 A7 94 81 CF 6F 45 .t8&2.........oE

Process client.exe (9288)
Debug Output:
CLI: Writing MAC params with salt, 500 iterations.

Process client.exe (9288)
Debug Output:
CLI   16 420E0835 C6 74 38 26 32 03 CB D3 DA B0 A7 94 81 CF 6F 45 .t8&2.........oE

Process client.exe (9288)
Debug Output:
CLI: Writing userID.

Process client.exe (9288)
Debug Output:
CLI    9 13200334 54 B4 2C EE 45 23 84 25 00                      T.,.E#.%.

Process client.exe (9288)
Thread Exit: Thread ID: 15640. Process client.exe (9288)
Thread Exit: Thread ID: 10884. Process client.exe (9288)


Server output:

SVR: Reading message type 26.
SVR: Read new userID.
SVR    9 13200334 54 B4 2C EE 45 23 84 25 00                      T.,.E#.%.
SVR: Read initial transID.
SVR   16 434C0747 77 94 6E 61 E4 32 A0 15 E0 DB 78 07 FB 02 10 5A w.na.2....x....Z
SVR: Read initial MAC params with salt, 500 iterations.
SVR   16 420E0835 C6 74 38 26 32 03 CB D3 DA B0 A7 94 81 CF 6F 45 .t8&2.........oE
d:\wymiana\projects\cryptlib\keyset\dbms.c:performQuery:237: Database backend return invalid data size.
The thread 0x38e4 has exited with code 3 (0x3).
The thread 0x3fb0 has exited with code 3 (0x3).
The thread 0x18b4 has exited with code 3 (0x3).
The thread 0x3b6c has exited with code 3 (0x3).
The program '[10796] CertServerProject1.exe' has exited with code 3 (0x3).

Best regards,
Tomasz


_______________________________________________
Cryptlib mailing list
[email protected] via Mail: [email protected]
Archive: ftp://ftp.franken.de/pub/crypt/cryptlib/archives/
http://news.gmane.org/gmane.comp.encryption.cryptlib
Posts from non-subscribed addresses are blocked to prevent spam, please
subscribe in order to post messages.