|
@@ -47,6 +47,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
47
|
47
|
#warning "Attempting to embed private key with no corresponding certificate"
|
48
|
48
|
#endif
|
49
|
49
|
|
|
50
|
+/* Allow client certificates to be overridden if not explicitly specified */
|
|
51
|
+#ifdef CERTIFICATE
|
|
52
|
+#define ALLOW_CERT_OVERRIDE 0
|
|
53
|
+#else
|
|
54
|
+#define ALLOW_CERT_OVERRIDE 1
|
|
55
|
+#endif
|
|
56
|
+
|
50
|
57
|
/* Raw client certificate data */
|
51
|
58
|
extern char client_certificate_data[];
|
52
|
59
|
extern char client_certificate_len[];
|
|
@@ -72,13 +79,19 @@ __asm__ ( ".section \".rodata\", \"a\", @progbits\n\t"
|
72
|
79
|
".previous\n\t" );
|
73
|
80
|
|
74
|
81
|
/** Client certificate */
|
75
|
|
-struct client_certificate client_certificate;
|
|
82
|
+struct client_certificate client_certificate = {
|
|
83
|
+ .data = client_certificate_data,
|
|
84
|
+ .len = ( ( size_t ) client_certificate_len ),
|
|
85
|
+};
|
76
|
86
|
|
77
|
87
|
/** Client private key */
|
78
|
|
-struct client_private_key client_private_key;
|
|
88
|
+struct client_private_key client_private_key = {
|
|
89
|
+ .data = client_private_key_data,
|
|
90
|
+ .len = ( ( size_t ) client_private_key_len ),
|
|
91
|
+};
|
79
|
92
|
|
80
|
93
|
/** Client certificate setting */
|
81
|
|
-struct setting cert_setting __setting ( SETTING_CRYPTO ) = {
|
|
94
|
+static struct setting cert_setting __setting ( SETTING_CRYPTO ) = {
|
82
|
95
|
.name = "cert",
|
83
|
96
|
.description = "Client certificate",
|
84
|
97
|
.tag = DHCP_EB_CERT,
|
|
@@ -86,7 +99,7 @@ struct setting cert_setting __setting ( SETTING_CRYPTO ) = {
|
86
|
99
|
};
|
87
|
100
|
|
88
|
101
|
/** Client private key setting */
|
89
|
|
-struct setting key_setting __setting ( SETTING_CRYPTO ) = {
|
|
102
|
+static struct setting key_setting __setting ( SETTING_CRYPTO ) = {
|
90
|
103
|
.name = "key",
|
91
|
104
|
.description = "Client private key",
|
92
|
105
|
.tag = DHCP_EB_KEY,
|
|
@@ -99,45 +112,51 @@ struct setting key_setting __setting ( SETTING_CRYPTO ) = {
|
99
|
112
|
* @ret rc Return status code
|
100
|
113
|
*/
|
101
|
114
|
static int clientcert_apply_settings ( void ) {
|
102
|
|
- static void *cert;
|
103
|
|
- static void *key;
|
|
115
|
+ static void *cert = NULL;
|
|
116
|
+ static void *key = NULL;
|
104
|
117
|
int len;
|
105
|
118
|
int rc;
|
106
|
119
|
|
107
|
|
- /* Restore default client certificate */
|
108
|
|
- client_certificate.data = client_certificate_data;
|
109
|
|
- client_certificate.len = ( ( size_t ) client_certificate_len );
|
110
|
|
-
|
111
|
|
- /* Fetch new client certificate, if any */
|
112
|
|
- free ( cert );
|
113
|
|
- len = fetch_setting_copy ( NULL, &cert_setting, &cert );
|
114
|
|
- if ( len < 0 ) {
|
115
|
|
- rc = len;
|
116
|
|
- DBGC ( &client_certificate, "CLIENTCERT cannot fetch client "
|
117
|
|
- "certificate: %s\n", strerror ( rc ) );
|
118
|
|
- return rc;
|
119
|
|
- }
|
120
|
|
- if ( cert ) {
|
121
|
|
- client_certificate.data = cert;
|
122
|
|
- client_certificate.len = len;
|
123
|
|
- }
|
124
|
|
-
|
125
|
|
- /* Restore default client private key */
|
126
|
|
- client_private_key.data = client_private_key_data;
|
127
|
|
- client_private_key.len = ( ( size_t ) client_private_key_len );
|
128
|
|
-
|
129
|
|
- /* Fetch new client private key, if any */
|
130
|
|
- free ( key );
|
131
|
|
- len = fetch_setting_copy ( NULL, &key_setting, &key );
|
132
|
|
- if ( len < 0 ) {
|
133
|
|
- rc = len;
|
134
|
|
- DBGC ( &client_certificate, "CLIENTCERT cannot fetch client "
|
135
|
|
- "private key: %s\n", strerror ( rc ) );
|
136
|
|
- return rc;
|
137
|
|
- }
|
138
|
|
- if ( key ) {
|
139
|
|
- client_private_key.data = key;
|
140
|
|
- client_private_key.len = len;
|
|
120
|
+ /* Allow client certificate to be overridden only if
|
|
121
|
+ * not explicitly specified at build time.
|
|
122
|
+ */
|
|
123
|
+ if ( ALLOW_CERT_OVERRIDE ) {
|
|
124
|
+
|
|
125
|
+ /* Restore default client certificate */
|
|
126
|
+ client_certificate.data = client_certificate_data;
|
|
127
|
+ client_certificate.len = ( ( size_t ) client_certificate_len );
|
|
128
|
+
|
|
129
|
+ /* Fetch new client certificate, if any */
|
|
130
|
+ free ( cert );
|
|
131
|
+ len = fetch_setting_copy ( NULL, &cert_setting, &cert );
|
|
132
|
+ if ( len < 0 ) {
|
|
133
|
+ rc = len;
|
|
134
|
+ DBGC ( &client_certificate, "CLIENTCERT cannot fetch "
|
|
135
|
+ "client certificate: %s\n", strerror ( rc ) );
|
|
136
|
+ return rc;
|
|
137
|
+ }
|
|
138
|
+ if ( cert ) {
|
|
139
|
+ client_certificate.data = cert;
|
|
140
|
+ client_certificate.len = len;
|
|
141
|
+ }
|
|
142
|
+
|
|
143
|
+ /* Restore default client private key */
|
|
144
|
+ client_private_key.data = client_private_key_data;
|
|
145
|
+ client_private_key.len = ( ( size_t ) client_private_key_len );
|
|
146
|
+
|
|
147
|
+ /* Fetch new client private key, if any */
|
|
148
|
+ free ( key );
|
|
149
|
+ len = fetch_setting_copy ( NULL, &key_setting, &key );
|
|
150
|
+ if ( len < 0 ) {
|
|
151
|
+ rc = len;
|
|
152
|
+ DBGC ( &client_certificate, "CLIENTCERT cannot fetch "
|
|
153
|
+ "client private key: %s\n", strerror ( rc ) );
|
|
154
|
+ return rc;
|
|
155
|
+ }
|
|
156
|
+ if ( key ) {
|
|
157
|
+ client_private_key.data = key;
|
|
158
|
+ client_private_key.len = len;
|
|
159
|
+ }
|
141
|
160
|
}
|
142
|
161
|
|
143
|
162
|
/* Debug */
|