< prev index next >

src/jdk.crypto.mscapi/windows/native/libsunmscapi/security.cpp

Print this page
rev 12879 : 8136556: Add the ability to perform static builds of MacOSX x64 binaries
Reviewed-by: ihse, bdelsart, gadams, lfoltan, rriggs, hseigel, twisti
   1 /*
   2  * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 //=--------------------------------------------------------------------------=
  27 // security.cpp    by Stanley Man-Kit Ho
  28 //=--------------------------------------------------------------------------=
  29 //
  30 
  31 #include <jni.h>

  32 #include <stdlib.h>
  33 #include <string.h>
  34 #include <windows.h>
  35 #include <BaseTsd.h>
  36 #include <wincrypt.h>
  37 #include <stdio.h>
  38 
  39 
  40 #define OID_EKU_ANY         "2.5.29.37.0"
  41 
  42 #define CERTIFICATE_PARSING_EXCEPTION \
  43                             "java/security/cert/CertificateParsingException"
  44 #define INVALID_KEY_EXCEPTION \
  45                             "java/security/InvalidKeyException"
  46 #define KEY_EXCEPTION       "java/security/KeyException"
  47 #define KEYSTORE_EXCEPTION  "java/security/KeyStoreException"
  48 #define PROVIDER_EXCEPTION  "java/security/ProviderException"
  49 #define SIGNATURE_EXCEPTION "java/security/SignatureException"
  50 
  51 extern "C" {





  52 
  53 /*
  54  * Throws an arbitrary Java exception.
  55  * The exception message is a Windows system error message.
  56  */
  57 void ThrowException(JNIEnv *env, char *exceptionName, DWORD dwError)
  58 {
  59     char szMessage[1024];
  60     szMessage[0] = '\0';
  61 
  62     DWORD res = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
  63         NULL, szMessage, sizeof(szMessage), NULL);
  64     if (res == 0) {
  65         strcpy(szMessage, "Unknown error");
  66     }
  67 
  68     jclass exceptionClazz = env->FindClass(exceptionName);
  69     if (exceptionClazz != NULL) {
  70         env->ThrowNew(exceptionClazz, szMessage);
  71     }


   1 /*
   2  * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 //=--------------------------------------------------------------------------=
  27 // security.cpp    by Stanley Man-Kit Ho
  28 //=--------------------------------------------------------------------------=
  29 //
  30 
  31 #include <jni.h>
  32 #include "jni_util.h"
  33 #include <stdlib.h>
  34 #include <string.h>
  35 #include <windows.h>
  36 #include <BaseTsd.h>
  37 #include <wincrypt.h>
  38 #include <stdio.h>
  39 
  40 
  41 #define OID_EKU_ANY         "2.5.29.37.0"
  42 
  43 #define CERTIFICATE_PARSING_EXCEPTION \
  44                             "java/security/cert/CertificateParsingException"
  45 #define INVALID_KEY_EXCEPTION \
  46                             "java/security/InvalidKeyException"
  47 #define KEY_EXCEPTION       "java/security/KeyException"
  48 #define KEYSTORE_EXCEPTION  "java/security/KeyStoreException"
  49 #define PROVIDER_EXCEPTION  "java/security/ProviderException"
  50 #define SIGNATURE_EXCEPTION "java/security/SignatureException"
  51 
  52 extern "C" {
  53 
  54 /*
  55  * Declare library specific JNI_Onload entry if static build
  56  */
  57 DEF_STATIC_JNI_OnLoad
  58 
  59 /*
  60  * Throws an arbitrary Java exception.
  61  * The exception message is a Windows system error message.
  62  */
  63 void ThrowException(JNIEnv *env, char *exceptionName, DWORD dwError)
  64 {
  65     char szMessage[1024];
  66     szMessage[0] = '\0';
  67 
  68     DWORD res = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
  69         NULL, szMessage, sizeof(szMessage), NULL);
  70     if (res == 0) {
  71         strcpy(szMessage, "Unknown error");
  72     }
  73 
  74     jclass exceptionClazz = env->FindClass(exceptionName);
  75     if (exceptionClazz != NULL) {
  76         env->ThrowNew(exceptionClazz, szMessage);
  77     }


< prev index next >