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