Fossil SCM

Merge SSL client certificate support from ben-security branch

ben 2011-06-02 19:31 UTC ben-testing merge
Commit 397f434a4dd6d318a549616859c8e0e14c953779
--- src/clone.c
+++ src/clone.c
@@ -37,10 +37,11 @@
3737
**
3838
** Options:
3939
**
4040
** --admin-user|-A USERNAME Make USERNAME the administrator
4141
** --private Also clone private branches
42
+** --ssl-identity=filename Use the SSL identity if requested by the server
4243
**
4344
*/
4445
void clone_cmd(void){
4546
char *zPassword;
4647
const char *zDefaultUser; /* Optional name of the default user */
@@ -91,10 +92,18 @@
9192
db_initial_setup(0, zDefaultUser, 0);
9293
user_select();
9394
db_set("content-schema", CONTENT_SCHEMA, 0);
9495
db_set("aux-schema", AUX_SCHEMA, 0);
9596
db_set("last-sync-url", g.argv[2], 0);
97
+ if( g.zSSLIdentity!=0 ){
98
+ /* If the --ssl-identity option was specified, store it as a setting */
99
+ Blob fn;
100
+ blob_zero(&fn);
101
+ file_canonical_name(g.zSSLIdentity, &fn);
102
+ db_set("ssl-identity", blob_str(&fn), 0);
103
+ blob_reset(&fn);
104
+ }
96105
db_multi_exec(
97106
"REPLACE INTO config(name,value,mtime)"
98107
" VALUES('server-code', lower(hex(randomblob(20))), now());"
99108
);
100109
url_enable_proxy(0);
101110
--- src/clone.c
+++ src/clone.c
@@ -37,10 +37,11 @@
37 **
38 ** Options:
39 **
40 ** --admin-user|-A USERNAME Make USERNAME the administrator
41 ** --private Also clone private branches
 
42 **
43 */
44 void clone_cmd(void){
45 char *zPassword;
46 const char *zDefaultUser; /* Optional name of the default user */
@@ -91,10 +92,18 @@
91 db_initial_setup(0, zDefaultUser, 0);
92 user_select();
93 db_set("content-schema", CONTENT_SCHEMA, 0);
94 db_set("aux-schema", AUX_SCHEMA, 0);
95 db_set("last-sync-url", g.argv[2], 0);
 
 
 
 
 
 
 
 
96 db_multi_exec(
97 "REPLACE INTO config(name,value,mtime)"
98 " VALUES('server-code', lower(hex(randomblob(20))), now());"
99 );
100 url_enable_proxy(0);
101
--- src/clone.c
+++ src/clone.c
@@ -37,10 +37,11 @@
37 **
38 ** Options:
39 **
40 ** --admin-user|-A USERNAME Make USERNAME the administrator
41 ** --private Also clone private branches
42 ** --ssl-identity=filename Use the SSL identity if requested by the server
43 **
44 */
45 void clone_cmd(void){
46 char *zPassword;
47 const char *zDefaultUser; /* Optional name of the default user */
@@ -91,10 +92,18 @@
92 db_initial_setup(0, zDefaultUser, 0);
93 user_select();
94 db_set("content-schema", CONTENT_SCHEMA, 0);
95 db_set("aux-schema", AUX_SCHEMA, 0);
96 db_set("last-sync-url", g.argv[2], 0);
97 if( g.zSSLIdentity!=0 ){
98 /* If the --ssl-identity option was specified, store it as a setting */
99 Blob fn;
100 blob_zero(&fn);
101 file_canonical_name(g.zSSLIdentity, &fn);
102 db_set("ssl-identity", blob_str(&fn), 0);
103 blob_reset(&fn);
104 }
105 db_multi_exec(
106 "REPLACE INTO config(name,value,mtime)"
107 " VALUES('server-code', lower(hex(randomblob(20))), now());"
108 );
109 url_enable_proxy(0);
110
+8
--- src/db.c
+++ src/db.c
@@ -1664,10 +1664,11 @@
16641664
{ "mtime-changes", 0, 0, "on" },
16651665
{ "pgp-command", 0, 32, "gpg --clearsign -o " },
16661666
{ "proxy", 0, 32, "off" },
16671667
{ "repo-cksum", 0, 0, "on" },
16681668
{ "self-register", 0, 0, "off" },
1669
+ { "ssl-identity", 0, 40, "" },
16691670
{ "ssh-command", 0, 32, "" },
16701671
{ "web-browser", 0, 32, "" },
16711672
{ 0,0,0,0 }
16721673
};
16731674
@@ -1773,10 +1774,17 @@
17731774
**
17741775
** self-register Allow users to register themselves through the HTTP UI.
17751776
** This is useful if you want to see other names than
17761777
** "Anonymous" in e.g. ticketing system. On the other hand
17771778
** users can not be deleted. Default: off.
1779
+**
1780
+** ssl-identity The full pathname to a file containing a certificate
1781
+** and private key in PEM format. Create by concatenating
1782
+** the certificate and private key files.
1783
+** This identity will be presented to SSL servers to
1784
+** authenticate this client, in addition to the normal
1785
+** password authentication.
17781786
**
17791787
** ssh-command Command used to talk to a remote machine with
17801788
** the "ssh://" protocol.
17811789
**
17821790
** web-browser A shell command used to launch your preferred
17831791
--- src/db.c
+++ src/db.c
@@ -1664,10 +1664,11 @@
1664 { "mtime-changes", 0, 0, "on" },
1665 { "pgp-command", 0, 32, "gpg --clearsign -o " },
1666 { "proxy", 0, 32, "off" },
1667 { "repo-cksum", 0, 0, "on" },
1668 { "self-register", 0, 0, "off" },
 
1669 { "ssh-command", 0, 32, "" },
1670 { "web-browser", 0, 32, "" },
1671 { 0,0,0,0 }
1672 };
1673
@@ -1773,10 +1774,17 @@
1773 **
1774 ** self-register Allow users to register themselves through the HTTP UI.
1775 ** This is useful if you want to see other names than
1776 ** "Anonymous" in e.g. ticketing system. On the other hand
1777 ** users can not be deleted. Default: off.
 
 
 
 
 
 
 
1778 **
1779 ** ssh-command Command used to talk to a remote machine with
1780 ** the "ssh://" protocol.
1781 **
1782 ** web-browser A shell command used to launch your preferred
1783
--- src/db.c
+++ src/db.c
@@ -1664,10 +1664,11 @@
1664 { "mtime-changes", 0, 0, "on" },
1665 { "pgp-command", 0, 32, "gpg --clearsign -o " },
1666 { "proxy", 0, 32, "off" },
1667 { "repo-cksum", 0, 0, "on" },
1668 { "self-register", 0, 0, "off" },
1669 { "ssl-identity", 0, 40, "" },
1670 { "ssh-command", 0, 32, "" },
1671 { "web-browser", 0, 32, "" },
1672 { 0,0,0,0 }
1673 };
1674
@@ -1773,10 +1774,17 @@
1774 **
1775 ** self-register Allow users to register themselves through the HTTP UI.
1776 ** This is useful if you want to see other names than
1777 ** "Anonymous" in e.g. ticketing system. On the other hand
1778 ** users can not be deleted. Default: off.
1779 **
1780 ** ssl-identity The full pathname to a file containing a certificate
1781 ** and private key in PEM format. Create by concatenating
1782 ** the certificate and private key files.
1783 ** This identity will be presented to SSL servers to
1784 ** authenticate this client, in addition to the normal
1785 ** password authentication.
1786 **
1787 ** ssh-command Command used to talk to a remote machine with
1788 ** the "ssh://" protocol.
1789 **
1790 ** web-browser A shell command used to launch your preferred
1791
+8
--- src/db.c
+++ src/db.c
@@ -1664,10 +1664,11 @@
16641664
{ "mtime-changes", 0, 0, "on" },
16651665
{ "pgp-command", 0, 32, "gpg --clearsign -o " },
16661666
{ "proxy", 0, 32, "off" },
16671667
{ "repo-cksum", 0, 0, "on" },
16681668
{ "self-register", 0, 0, "off" },
1669
+ { "ssl-identity", 0, 40, "" },
16691670
{ "ssh-command", 0, 32, "" },
16701671
{ "web-browser", 0, 32, "" },
16711672
{ 0,0,0,0 }
16721673
};
16731674
@@ -1773,10 +1774,17 @@
17731774
**
17741775
** self-register Allow users to register themselves through the HTTP UI.
17751776
** This is useful if you want to see other names than
17761777
** "Anonymous" in e.g. ticketing system. On the other hand
17771778
** users can not be deleted. Default: off.
1779
+**
1780
+** ssl-identity The full pathname to a file containing a certificate
1781
+** and private key in PEM format. Create by concatenating
1782
+** the certificate and private key files.
1783
+** This identity will be presented to SSL servers to
1784
+** authenticate this client, in addition to the normal
1785
+** password authentication.
17781786
**
17791787
** ssh-command Command used to talk to a remote machine with
17801788
** the "ssh://" protocol.
17811789
**
17821790
** web-browser A shell command used to launch your preferred
17831791
--- src/db.c
+++ src/db.c
@@ -1664,10 +1664,11 @@
1664 { "mtime-changes", 0, 0, "on" },
1665 { "pgp-command", 0, 32, "gpg --clearsign -o " },
1666 { "proxy", 0, 32, "off" },
1667 { "repo-cksum", 0, 0, "on" },
1668 { "self-register", 0, 0, "off" },
 
1669 { "ssh-command", 0, 32, "" },
1670 { "web-browser", 0, 32, "" },
1671 { 0,0,0,0 }
1672 };
1673
@@ -1773,10 +1774,17 @@
1773 **
1774 ** self-register Allow users to register themselves through the HTTP UI.
1775 ** This is useful if you want to see other names than
1776 ** "Anonymous" in e.g. ticketing system. On the other hand
1777 ** users can not be deleted. Default: off.
 
 
 
 
 
 
 
1778 **
1779 ** ssh-command Command used to talk to a remote machine with
1780 ** the "ssh://" protocol.
1781 **
1782 ** web-browser A shell command used to launch your preferred
1783
--- src/db.c
+++ src/db.c
@@ -1664,10 +1664,11 @@
1664 { "mtime-changes", 0, 0, "on" },
1665 { "pgp-command", 0, 32, "gpg --clearsign -o " },
1666 { "proxy", 0, 32, "off" },
1667 { "repo-cksum", 0, 0, "on" },
1668 { "self-register", 0, 0, "off" },
1669 { "ssl-identity", 0, 40, "" },
1670 { "ssh-command", 0, 32, "" },
1671 { "web-browser", 0, 32, "" },
1672 { 0,0,0,0 }
1673 };
1674
@@ -1773,10 +1774,17 @@
1774 **
1775 ** self-register Allow users to register themselves through the HTTP UI.
1776 ** This is useful if you want to see other names than
1777 ** "Anonymous" in e.g. ticketing system. On the other hand
1778 ** users can not be deleted. Default: off.
1779 **
1780 ** ssl-identity The full pathname to a file containing a certificate
1781 ** and private key in PEM format. Create by concatenating
1782 ** the certificate and private key files.
1783 ** This identity will be presented to SSL servers to
1784 ** authenticate this client, in addition to the normal
1785 ** password authentication.
1786 **
1787 ** ssh-command Command used to talk to a remote machine with
1788 ** the "ssh://" protocol.
1789 **
1790 ** web-browser A shell command used to launch your preferred
1791
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -78,10 +78,19 @@
7878
** Return the current SSL error message
7979
*/
8080
const char *ssl_errmsg(void){
8181
return sslErrMsg;
8282
}
83
+
84
+/*
85
+** When a server requests a client certificate that hasn't been provided,
86
+** display a warning message explaining what to do next.
87
+*/
88
+static int ssl_client_cert_callback(SSL *ssl, X509 **x509, EVP_PKEY **pkey){
89
+ fossil_warning("The remote server requested a client certificate for authentication. Specify the pathname to a file containing the PEM encoded certificate and private key with the --ssl-identity option or the ssl-identity setting.");
90
+ return 0; /* no cert available */
91
+}
8392
8493
/*
8594
** Call this routine once before any other use of the SSL interface.
8695
** This routine does initial configuration of the SSL module.
8796
*/
@@ -91,10 +100,22 @@
91100
SSL_load_error_strings();
92101
ERR_load_BIO_strings();
93102
OpenSSL_add_all_algorithms();
94103
sslCtx = SSL_CTX_new(SSLv23_client_method());
95104
X509_STORE_set_default_paths(SSL_CTX_get_cert_store(sslCtx));
105
+
106
+ /* Load client SSL identity, preferring the filename specified on the command line */
107
+ const char *identityFile = ( g.zSSLIdentity!= 0) ? g.zSSLIdentity : db_get("ssl-identity", 0);
108
+ if( identityFile!=0 && identityFile[0]!='\0' ){
109
+ if( SSL_CTX_use_certificate_file(sslCtx, identityFile, SSL_FILETYPE_PEM)!= 1
110
+ || SSL_CTX_use_PrivateKey_file(sslCtx, identityFile, SSL_FILETYPE_PEM)!=1 ){
111
+ fossil_fatal("Could not load SSL identity from %s", identityFile);
112
+ }
113
+ }
114
+ /* Register a callback to tell the user what to do when the server asks for a cert */
115
+ SSL_CTX_set_client_cert_cb(sslCtx, ssl_client_cert_callback);
116
+
96117
sslIsInit = 1;
97118
}
98119
}
99120
100121
/*
101122
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -78,10 +78,19 @@
78 ** Return the current SSL error message
79 */
80 const char *ssl_errmsg(void){
81 return sslErrMsg;
82 }
 
 
 
 
 
 
 
 
 
83
84 /*
85 ** Call this routine once before any other use of the SSL interface.
86 ** This routine does initial configuration of the SSL module.
87 */
@@ -91,10 +100,22 @@
91 SSL_load_error_strings();
92 ERR_load_BIO_strings();
93 OpenSSL_add_all_algorithms();
94 sslCtx = SSL_CTX_new(SSLv23_client_method());
95 X509_STORE_set_default_paths(SSL_CTX_get_cert_store(sslCtx));
 
 
 
 
 
 
 
 
 
 
 
 
96 sslIsInit = 1;
97 }
98 }
99
100 /*
101
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -78,10 +78,19 @@
78 ** Return the current SSL error message
79 */
80 const char *ssl_errmsg(void){
81 return sslErrMsg;
82 }
83
84 /*
85 ** When a server requests a client certificate that hasn't been provided,
86 ** display a warning message explaining what to do next.
87 */
88 static int ssl_client_cert_callback(SSL *ssl, X509 **x509, EVP_PKEY **pkey){
89 fossil_warning("The remote server requested a client certificate for authentication. Specify the pathname to a file containing the PEM encoded certificate and private key with the --ssl-identity option or the ssl-identity setting.");
90 return 0; /* no cert available */
91 }
92
93 /*
94 ** Call this routine once before any other use of the SSL interface.
95 ** This routine does initial configuration of the SSL module.
96 */
@@ -91,10 +100,22 @@
100 SSL_load_error_strings();
101 ERR_load_BIO_strings();
102 OpenSSL_add_all_algorithms();
103 sslCtx = SSL_CTX_new(SSLv23_client_method());
104 X509_STORE_set_default_paths(SSL_CTX_get_cert_store(sslCtx));
105
106 /* Load client SSL identity, preferring the filename specified on the command line */
107 const char *identityFile = ( g.zSSLIdentity!= 0) ? g.zSSLIdentity : db_get("ssl-identity", 0);
108 if( identityFile!=0 && identityFile[0]!='\0' ){
109 if( SSL_CTX_use_certificate_file(sslCtx, identityFile, SSL_FILETYPE_PEM)!= 1
110 || SSL_CTX_use_PrivateKey_file(sslCtx, identityFile, SSL_FILETYPE_PEM)!=1 ){
111 fossil_fatal("Could not load SSL identity from %s", identityFile);
112 }
113 }
114 /* Register a callback to tell the user what to do when the server asks for a cert */
115 SSL_CTX_set_client_cert_cb(sslCtx, ssl_client_cert_callback);
116
117 sslIsInit = 1;
118 }
119 }
120
121 /*
122
+2
--- src/main.c
+++ src/main.c
@@ -105,10 +105,11 @@
105105
char *urlProxyAuth; /* Proxy-Authorizer: string */
106106
char *urlFossil; /* The path of the ?fossil=path suffix on ssh: */
107107
int dontKeepUrl; /* Do not persist the URL */
108108
109109
const char *zLogin; /* Login name. "" if not logged in. */
110
+ const char *zSSLIdentity; /* Value of --ssl-identity option, filename of SSL client identity */
110111
int useLocalauth; /* No login required if from 127.0.0.1 */
111112
int noPswd; /* Logged in without password (on 127.0.0.1) */
112113
int userUid; /* Integer user id */
113114
114115
/* Information used to populate the RCVFROM table */
@@ -251,10 +252,11 @@
251252
g.fSystemTrace = find_option("systemtrace", 0, 0)!=0;
252253
if( g.fSqlTrace ) g.fSqlStats = 1;
253254
g.fSqlPrint = find_option("sqlprint", 0, 0)!=0;
254255
g.fHttpTrace = find_option("httptrace", 0, 0)!=0;
255256
g.zLogin = find_option("user", "U", 1);
257
+ g.zSSLIdentity = find_option("ssl-identity", 0, 1);
256258
if( find_option("help",0,0)!=0 ){
257259
/* --help anywhere on the command line is translated into
258260
** "fossil help argv[1] argv[2]..." */
259261
int i;
260262
char **zNewArgv = fossil_malloc( sizeof(char*)*(g.argc+2) );
261263
--- src/main.c
+++ src/main.c
@@ -105,10 +105,11 @@
105 char *urlProxyAuth; /* Proxy-Authorizer: string */
106 char *urlFossil; /* The path of the ?fossil=path suffix on ssh: */
107 int dontKeepUrl; /* Do not persist the URL */
108
109 const char *zLogin; /* Login name. "" if not logged in. */
 
110 int useLocalauth; /* No login required if from 127.0.0.1 */
111 int noPswd; /* Logged in without password (on 127.0.0.1) */
112 int userUid; /* Integer user id */
113
114 /* Information used to populate the RCVFROM table */
@@ -251,10 +252,11 @@
251 g.fSystemTrace = find_option("systemtrace", 0, 0)!=0;
252 if( g.fSqlTrace ) g.fSqlStats = 1;
253 g.fSqlPrint = find_option("sqlprint", 0, 0)!=0;
254 g.fHttpTrace = find_option("httptrace", 0, 0)!=0;
255 g.zLogin = find_option("user", "U", 1);
 
256 if( find_option("help",0,0)!=0 ){
257 /* --help anywhere on the command line is translated into
258 ** "fossil help argv[1] argv[2]..." */
259 int i;
260 char **zNewArgv = fossil_malloc( sizeof(char*)*(g.argc+2) );
261
--- src/main.c
+++ src/main.c
@@ -105,10 +105,11 @@
105 char *urlProxyAuth; /* Proxy-Authorizer: string */
106 char *urlFossil; /* The path of the ?fossil=path suffix on ssh: */
107 int dontKeepUrl; /* Do not persist the URL */
108
109 const char *zLogin; /* Login name. "" if not logged in. */
110 const char *zSSLIdentity; /* Value of --ssl-identity option, filename of SSL client identity */
111 int useLocalauth; /* No login required if from 127.0.0.1 */
112 int noPswd; /* Logged in without password (on 127.0.0.1) */
113 int userUid; /* Integer user id */
114
115 /* Information used to populate the RCVFROM table */
@@ -251,10 +252,11 @@
252 g.fSystemTrace = find_option("systemtrace", 0, 0)!=0;
253 if( g.fSqlTrace ) g.fSqlStats = 1;
254 g.fSqlPrint = find_option("sqlprint", 0, 0)!=0;
255 g.fHttpTrace = find_option("httptrace", 0, 0)!=0;
256 g.zLogin = find_option("user", "U", 1);
257 g.zSSLIdentity = find_option("ssl-identity", 0, 1);
258 if( find_option("help",0,0)!=0 ){
259 /* --help anywhere on the command line is translated into
260 ** "fossil help argv[1] argv[2]..." */
261 int i;
262 char **zNewArgv = fossil_malloc( sizeof(char*)*(g.argc+2) );
263
+2
--- src/main.c
+++ src/main.c
@@ -105,10 +105,11 @@
105105
char *urlProxyAuth; /* Proxy-Authorizer: string */
106106
char *urlFossil; /* The path of the ?fossil=path suffix on ssh: */
107107
int dontKeepUrl; /* Do not persist the URL */
108108
109109
const char *zLogin; /* Login name. "" if not logged in. */
110
+ const char *zSSLIdentity; /* Value of --ssl-identity option, filename of SSL client identity */
110111
int useLocalauth; /* No login required if from 127.0.0.1 */
111112
int noPswd; /* Logged in without password (on 127.0.0.1) */
112113
int userUid; /* Integer user id */
113114
114115
/* Information used to populate the RCVFROM table */
@@ -251,10 +252,11 @@
251252
g.fSystemTrace = find_option("systemtrace", 0, 0)!=0;
252253
if( g.fSqlTrace ) g.fSqlStats = 1;
253254
g.fSqlPrint = find_option("sqlprint", 0, 0)!=0;
254255
g.fHttpTrace = find_option("httptrace", 0, 0)!=0;
255256
g.zLogin = find_option("user", "U", 1);
257
+ g.zSSLIdentity = find_option("ssl-identity", 0, 1);
256258
if( find_option("help",0,0)!=0 ){
257259
/* --help anywhere on the command line is translated into
258260
** "fossil help argv[1] argv[2]..." */
259261
int i;
260262
char **zNewArgv = fossil_malloc( sizeof(char*)*(g.argc+2) );
261263
--- src/main.c
+++ src/main.c
@@ -105,10 +105,11 @@
105 char *urlProxyAuth; /* Proxy-Authorizer: string */
106 char *urlFossil; /* The path of the ?fossil=path suffix on ssh: */
107 int dontKeepUrl; /* Do not persist the URL */
108
109 const char *zLogin; /* Login name. "" if not logged in. */
 
110 int useLocalauth; /* No login required if from 127.0.0.1 */
111 int noPswd; /* Logged in without password (on 127.0.0.1) */
112 int userUid; /* Integer user id */
113
114 /* Information used to populate the RCVFROM table */
@@ -251,10 +252,11 @@
251 g.fSystemTrace = find_option("systemtrace", 0, 0)!=0;
252 if( g.fSqlTrace ) g.fSqlStats = 1;
253 g.fSqlPrint = find_option("sqlprint", 0, 0)!=0;
254 g.fHttpTrace = find_option("httptrace", 0, 0)!=0;
255 g.zLogin = find_option("user", "U", 1);
 
256 if( find_option("help",0,0)!=0 ){
257 /* --help anywhere on the command line is translated into
258 ** "fossil help argv[1] argv[2]..." */
259 int i;
260 char **zNewArgv = fossil_malloc( sizeof(char*)*(g.argc+2) );
261
--- src/main.c
+++ src/main.c
@@ -105,10 +105,11 @@
105 char *urlProxyAuth; /* Proxy-Authorizer: string */
106 char *urlFossil; /* The path of the ?fossil=path suffix on ssh: */
107 int dontKeepUrl; /* Do not persist the URL */
108
109 const char *zLogin; /* Login name. "" if not logged in. */
110 const char *zSSLIdentity; /* Value of --ssl-identity option, filename of SSL client identity */
111 int useLocalauth; /* No login required if from 127.0.0.1 */
112 int noPswd; /* Logged in without password (on 127.0.0.1) */
113 int userUid; /* Integer user id */
114
115 /* Information used to populate the RCVFROM table */
@@ -251,10 +252,11 @@
252 g.fSystemTrace = find_option("systemtrace", 0, 0)!=0;
253 if( g.fSqlTrace ) g.fSqlStats = 1;
254 g.fSqlPrint = find_option("sqlprint", 0, 0)!=0;
255 g.fHttpTrace = find_option("httptrace", 0, 0)!=0;
256 g.zLogin = find_option("user", "U", 1);
257 g.zSSLIdentity = find_option("ssl-identity", 0, 1);
258 if( find_option("help",0,0)!=0 ){
259 /* --help anywhere on the command line is translated into
260 ** "fossil help argv[1] argv[2]..." */
261 int i;
262 char **zNewArgv = fossil_malloc( sizeof(char*)*(g.argc+2) );
263

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button