javaextensions/satsa/pki/src.s60/cmsmessagesignatureservice.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include <stdlib.h>
       
    21 #include <string.h>
       
    22 
       
    23 #include "javax_microedition_securityservice_CMSMessageSignatureService.h"
       
    24 #include "cstssignatureservice.h"
       
    25 #include "satsajnitools.h"
       
    26 #include "logger.h"
       
    27 #include "javajniutils.h"
       
    28 #include "jniarrayutils.h"
       
    29 #include "s60commonutils.h"
       
    30 
       
    31 
       
    32 
       
    33 JNIEXPORT jint JNICALL
       
    34 Java_javax_microedition_securityservice_CMSMessageSignatureService__1createSignatureService(
       
    35     JNIEnv* /* aJniEnv */,
       
    36     jobject /* aPeer */)
       
    37 {
       
    38     LOG(ESATSA, EInfo, "+ Entering JNI function __1createSignatureService");
       
    39     CSTSSignatureService* service = NULL;
       
    40     TInt serviceHandle = KErrGeneral;
       
    41     TRAPD(error, service = CSTSSignatureService::NewL());
       
    42     if (service == NULL || KErrNone != error)
       
    43     {
       
    44         return error;
       
    45     }
       
    46     serviceHandle = reinterpret_cast<TInt>(service);
       
    47     LOG(ESATSA, EInfo, "--  __1createSignatureService");
       
    48     return serviceHandle;
       
    49 
       
    50 }
       
    51 
       
    52 JNIEXPORT jbyteArray
       
    53 JNICALL Java_javax_microedition_securityservice_CMSMessageSignatureService__1authenticate(
       
    54     JNIEnv* aJniEnv,
       
    55     jobject /* aPeer */,
       
    56     jint aServiceHandle,
       
    57     jbyteArray aByteArrayToAuthenticate, jint aOptions, jobjectArray aCaNames,
       
    58     jstring aSecurityElementPrompt, jboolean aShowData, jintArray aError)
       
    59 {
       
    60     LOG(ESATSA, EInfo, "+ Entering JNI function __1authenticate");
       
    61     CSTSSignatureService* service =
       
    62         reinterpret_cast<CSTSSignatureService *>(aServiceHandle);
       
    63 
       
    64     HBufC8* retVal = NULL;
       
    65     int ret=0;
       
    66 
       
    67     TRAPD(err, ret = CSTSSignatureService::StaticAuthenticateL(aJniEnv,
       
    68                      service, aByteArrayToAuthenticate, aOptions, aCaNames,
       
    69                      aSecurityElementPrompt, aShowData, &retVal));
       
    70     LOG(ESATSA, EInfo, "__1authenticate:After the call to StaticAuthenticateL");
       
    71 
       
    72     STSSetJavaErrorCode(aJniEnv, aError, ret);
       
    73     if ((ret != KErrNone) || (!retVal) || (KErrNone != err))
       
    74     {
       
    75         LOG(ESATSA, EInfo, "__1authenticate:Error !! ");
       
    76         return NULL;
       
    77     }
       
    78 
       
    79     const TInt numElems = retVal->Length();
       
    80     jbyteArray javaValue = aJniEnv->NewByteArray(numElems);
       
    81 
       
    82     if (!javaValue)
       
    83     {
       
    84         LOG(ESATSA, EInfo, "__1authenticate:No Memory !! ");
       
    85         STSSetJavaErrorCode(aJniEnv, aError, KErrNoMemory);
       
    86         delete retVal;
       
    87     }
       
    88 
       
    89     if (numElems> 0)
       
    90     {
       
    91         LOG(ESATSA, EInfo, "__1authenticate:COpy to Java");
       
    92         aJniEnv->SetByteArrayRegion(
       
    93             javaValue, 0, numElems,
       
    94             JAVA_PTR(retVal->Ptr()));
       
    95     }
       
    96 
       
    97     delete retVal;
       
    98     LOG(ESATSA, EInfo, "-- __1authenticate");
       
    99     return javaValue;
       
   100 }
       
   101 
       
   102 JNIEXPORT jbyteArray
       
   103 JNICALL Java_javax_microedition_securityservice_CMSMessageSignatureService__1sign(
       
   104     JNIEnv* aJniEnv,
       
   105     jobject /* aPeer */,
       
   106     jint aServiceHandle,
       
   107     jbyteArray aByteArrayToSign, jint aOptions, jobjectArray aCaNames,
       
   108     jstring aSecurityElementPrompt, jintArray aError)
       
   109 {
       
   110     LOG(ESATSA, EInfo, "+ Entering JNI function __1sign");
       
   111 
       
   112     CSTSSignatureService* service =
       
   113         reinterpret_cast<CSTSSignatureService *>(aServiceHandle);
       
   114 
       
   115     HBufC8* retVal = NULL;
       
   116     int ret=0;
       
   117     TRAPD(err, ret = CSTSSignatureService::StaticSignL(aJniEnv, service, aByteArrayToSign, aOptions,
       
   118                      aCaNames, aSecurityElementPrompt, &retVal));
       
   119     LOG(ESATSA, EInfo, "__1sign:After the call to StaticSignL");
       
   120 
       
   121     STSSetJavaErrorCode(aJniEnv, aError, ret);
       
   122     if ((KErrNone != ret) || (!retVal) || (KErrNone != err))
       
   123     {
       
   124         return NULL;
       
   125     }
       
   126     const TInt numElems = retVal->Length();
       
   127     jbyteArray javaValue = aJniEnv->NewByteArray(numElems);
       
   128 
       
   129     if (!javaValue)
       
   130     {
       
   131         STSSetJavaErrorCode(aJniEnv, aError, KErrNoMemory);
       
   132         delete retVal;
       
   133     }
       
   134 
       
   135     if (numElems> 0)
       
   136     {
       
   137         aJniEnv->SetByteArrayRegion(
       
   138             javaValue, 0, numElems,
       
   139             JAVA_PTR(retVal->Ptr()));
       
   140     }
       
   141     delete retVal;
       
   142     LOG(ESATSA, EInfo, "--returning __1sign");
       
   143     return javaValue;
       
   144 }