• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2015 The Android Open Source Project
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License. */
14 
15 /* This program generates output that is expected to become
16  * NativeConstants.java. This reifies several OpenSSL constants into Java. */
17 
18 #include <stdio.h>
19 
20 #include <openssl/ec.h>
21 #include <openssl/rsa.h>
22 #include <openssl/ssl.h>
23 #include <openssl/x509v3.h>
24 #include <openssl/evp.h>
25 #include <openssl/aead.h>
26 
27 static const char kCopyright[] =
28     "/* Copyright (C) 2015 The Android Open Source Project\n"
29     " *\n"
30     " * Licensed under the Apache License, Version 2.0 (the \"License\");\n"
31     " * you may not use this file except in compliance with the License.\n"
32     " * You may obtain a copy of the License at\n"
33     " *\n"
34     " *      http://www.apache.org/licenses/LICENSE-2.0\n"
35     " *\n"
36     " * Unless required by applicable law or agreed to in writing, software\n"
37     " * distributed under the License is distributed on an \"AS IS\" BASIS,\n"
38     " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or "
39     "implied.\n"
40     " * See the License for the specific language governing permissions and\n"
41     " * limitations under the License. */\n";
42 
main(int argc,char ** argv)43 int main(int argc, char **argv) {
44   const char *package;
45   if (argc == 1) {
46     package = "org.conscrypt";
47   } else {
48     package = argv[1];
49   }
50   printf("%s\n", kCopyright);
51   printf("/* This file was generated by generate_constants.cc. */\n\n");
52   printf("package %s;\n\n", package);
53   printf("final class NativeConstants {\n");
54 
55 #define CONST(x) \
56   printf("    static final int %s = %ld;\n", #x, (long int)(x))
57 
58   CONST(EXFLAG_CA);
59   CONST(EXFLAG_CRITICAL);
60 
61   CONST(EVP_PKEY_RSA);
62   CONST(EVP_PKEY_EC);
63 
64   CONST(RSA_PKCS1_PADDING);
65   CONST(RSA_NO_PADDING);
66   CONST(RSA_PKCS1_OAEP_PADDING);
67   CONST(RSA_PKCS1_PSS_PADDING);
68 
69   CONST(SSL_MODE_SEND_FALLBACK_SCSV);
70   CONST(SSL_MODE_CBC_RECORD_SPLITTING);
71   CONST(SSL_MODE_ENABLE_FALSE_START);
72 
73   CONST(SSL_OP_CIPHER_SERVER_PREFERENCE);
74   CONST(SSL_OP_NO_TICKET);
75 
76   CONST(SSL_ERROR_NONE);
77   CONST(SSL_ERROR_WANT_READ);
78   CONST(SSL_ERROR_WANT_WRITE);
79   CONST(SSL_ERROR_ZERO_RETURN);
80 
81   CONST(TLS1_VERSION);
82   CONST(TLS1_1_VERSION);
83   CONST(TLS1_2_VERSION);
84   CONST(TLS1_3_VERSION);
85 
86   CONST(SSL_SENT_SHUTDOWN);
87   CONST(SSL_RECEIVED_SHUTDOWN);
88 
89   CONST(TLS_CT_RSA_SIGN);
90   CONST(TLS_CT_ECDSA_SIGN);
91 
92   CONST(SSL_SIGN_RSA_PKCS1_SHA1);
93   CONST(SSL_SIGN_RSA_PKCS1_SHA256);
94   CONST(SSL_SIGN_RSA_PKCS1_SHA384);
95   CONST(SSL_SIGN_RSA_PKCS1_SHA512);
96   CONST(SSL_SIGN_ECDSA_SHA1);
97   CONST(SSL_SIGN_ECDSA_SECP256R1_SHA256);
98   CONST(SSL_SIGN_ECDSA_SECP384R1_SHA384);
99   CONST(SSL_SIGN_ECDSA_SECP521R1_SHA512);
100   CONST(SSL_SIGN_RSA_PSS_RSAE_SHA256);
101   CONST(SSL_SIGN_RSA_PSS_RSAE_SHA384);
102   CONST(SSL_SIGN_RSA_PSS_RSAE_SHA512);
103   CONST(SSL_SIGN_ED25519);
104 
105   CONST(SSL_VERIFY_NONE);
106   CONST(SSL_VERIFY_PEER);
107   CONST(SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
108 
109   CONST(SSL_CB_HANDSHAKE_START);
110   CONST(SSL_CB_HANDSHAKE_DONE);
111 
112   CONST(SSL3_RT_MAX_PLAIN_LENGTH);
113   CONST(SSL3_RT_MAX_PACKET_SIZE);
114   CONST(SSL3_RT_CHANGE_CIPHER_SPEC);
115   CONST(SSL3_RT_ALERT);
116   CONST(SSL3_RT_HANDSHAKE);
117   CONST(SSL3_RT_APPLICATION_DATA);
118   CONST(SSL3_RT_HEADER_LENGTH);
119 #undef CONST
120 
121   printf("}\n");
122 
123   return 0;
124 }
125