javacommons/security/src/utils/securityutils.cpp
changeset 78 71ad690e91f5
parent 72 1f0034e370aa
equal deleted inserted replaced
72:1f0034e370aa 78:71ad690e91f5
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 #include <string.h>
    17 #include <string.h>
    18 #include "securityutils.h"
    18 #include "securityutils.h"
       
    19 #include <openssl/bn.h>
    19 #include "telutils.h"
    20 #include "telutils.h"
    20 #include "fileutils.h"
    21 #include "fileutils.h"
    21 #include "com_nokia_mj_impl_security_utils_TelUtils.h"
    22 #include "com_nokia_mj_impl_security_utils_TelUtils.h"
    22 
    23 
    23 using namespace java::security;
    24 using namespace java::security;
   305     details->notAfter = new char[15];
   306     details->notAfter = new char[15];
   306     strncpy(details->notAfter,(const char*)gTimeAfter->data, 14 /* the format is YYMMDDHHMMSSZ and we and we leave the Z out */);
   307     strncpy(details->notAfter,(const char*)gTimeAfter->data, 14 /* the format is YYMMDDHHMMSSZ and we and we leave the Z out */);
   307     details->notAfter[14] = '\0';
   308     details->notAfter[14] = '\0';
   308     ASN1_TIME_free(gTimeAfter);
   309     ASN1_TIME_free(gTimeAfter);
   309     // serial number
   310     // serial number
   310     ASN1_INTEGER* serial_number = X509_get_serialNumber(&cert);
   311     BIGNUM *bn = BN_new();
   311     details->serial_number = new char[10];
   312     ASN1_INTEGER_to_BN(X509_get_serialNumber(&cert), bn);
   312     unsigned char * int_serial_number = new unsigned char[20];
   313     details->serial_number = BN_bn2hex(bn);
   313     unsigned char * tmp_serial_number = int_serial_number;
   314     BN_free(bn);
   314     int len = i2c_ASN1_INTEGER(serial_number, &tmp_serial_number);
       
   315     if (len > 0)
       
   316     {
       
   317         // format it as hex
       
   318         sprintf(details->serial_number,"%08lX",int_serial_number);
       
   319         details->serial_number[8] = '\0';
       
   320     }
       
   321     delete[] int_serial_number;
       
   322     int_serial_number = NULL;
       
   323     tmp_serial_number = NULL;
       
   324     // fingerprint
   315     // fingerprint
   325     const EVP_MD * SHA1=EVP_sha1();
   316     const EVP_MD * SHA1=EVP_sha1();
   326     unsigned int n;
   317     unsigned int n;
   327     unsigned char * digest = new unsigned char[SHA_1_DIGEST_LEN];
   318     unsigned char * digest = new unsigned char[SHA_1_DIGEST_LEN];
   328     if (X509_digest(&cert,SHA1,digest,&n))
   319     if (X509_digest(&cert,SHA1,digest,&n))