Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Some rephrasing and code cleanup. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | jan-clientcert |
| Files: | files | file ages | folders |
| SHA1: |
cff102fe85949448d93305a246c02884 |
| User & Date: | jan 2011-03-31 15:30:45.063 |
Context
|
2011-04-02
| ||
| 13:40 | Use the dedicated certs table for server certificate cache. Only attempt to use client certificate if one was actually specified for a cert bundle. Assume client key is in same file as certificate if one wasn't explicitly specified. check-in: c44bb083e9 user: jan tags: jan-clientcert | |
|
2011-03-31
| ||
| 15:30 | Some rephrasing and code cleanup. check-in: cff102fe85 user: jan tags: jan-clientcert | |
|
2011-03-30
| ||
| 21:00 | Code cleanup. Fix the "cert" command so that it compiles even if FOSSIL_ENABLE_SSL is not used. check-in: ebe1faabbc user: drh tags: jan-clientcert | |
Changes
Changes to src/clone.c.
| ︙ | ︙ | |||
35 36 37 38 39 40 41 | ** admin user. This can be overridden using the -A|--admin-user ** parameter. ** ** Options: ** ** --admin-user|-A USERNAME Make USERNAME the administrator ** --private Also clone private branches | | | | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
** admin user. This can be overridden using the -A|--admin-user
** parameter.
**
** Options:
**
** --admin-user|-A USERNAME Make USERNAME the administrator
** --private Also clone private branches
** --certbundle NAME Use certificate bundle NAME for https
** connections
**
*/
void clone_cmd(void){
char *zPassword;
const char *zDefaultUser; /* Optional name of the default user */
int nErr = 0;
int bPrivate; /* Also clone private branches */
bPrivate = find_option("private",0,0)!=0;
g.urlCertBundle = find_option("certbundle",0,1);
url_proxy_options();
if( g.argc < 4 ){
usage("?OPTIONS? FILE-OR-URL NEW-REPOSITORY");
}
db_open_config(0);
if( file_size(g.argv[3])>0 ){
fossil_panic("file already exists: %s", g.argv[3]);
|
| ︙ | ︙ |
Changes to src/http_ssl.c.
| ︙ | ︙ | |||
307 308 309 310 311 312 313 |
N -= got;
pContent = (void*)&((char*)pContent)[got];
}
return total;
}
/*
| | | | | | | | | | | | | | | | | | | 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
N -= got;
pContent = (void*)&((char*)pContent)[got];
}
return total;
}
/*
** If a certbundle has been specified on the command line, then use it to look
** up certificates and keys, and then store the URL-certbundle association in
** the global database. If no certbundle has been specified on the command
** line, see if there's an entry for the url in global_config, and use it if
** applicable.
*/
void ssl_load_client_authfiles(void){
char *zBundleName = NULL;
char *cafile;
char *capath;
char *certfile;
char *keyfile;
if( g.urlCertBundle ){
char *zName;
zName = mprintf("certbundle:%s", g.urlName);
db_set(zName, g.urlCertBundle, 1);
free(zName);
zBundleName = strdup(g.urlCertBundle);
}else{
db_swap_connections();
zBundleName = db_text(0, "SELECT value FROM global_config"
" WHERE name='certbundle:%q'", g.urlName);
db_swap_connections();
}
if( !zBundleName ){
/* No cert bundle specified on command line or found cached for URL */
return;
}
db_swap_connections();
create_cert_table_if_not_exist();
cafile = db_text(0, "SELECT filepath FROM certs WHERE name=%Q"
" AND type='cafile'", zBundleName);
capath = db_text(0, "SELECT filepath FROM certs WHERE name=%Q"
" AND type='capath'", zBundleName);
db_swap_connections();
if( cafile || capath ){
/* The OpenSSL documentation warns that if several CA certificates match
** the same name, key identifier and serial number conditions, only the
** first will be examined. The caveat situation occurs when one stores an
** expired CA certificate among the valid ones.
** Simply put: Do not mix expired and valid certificates.
*/
if( SSL_CTX_load_verify_locations(sslCtx, cafile, capath)==0 ){
fossil_fatal("SSL: Unable to load CA verification file/path");
}
}
db_swap_connections();
keyfile = db_text(0, "SELECT filepath FROM certs WHERE name=%Q"
" AND type='ckey'", zBundleName);
certfile = db_text(0, "SELECT filepath FROM certs WHERE name=%Q"
" AND type='ccert'", zBundleName);
db_swap_connections();
if( SSL_CTX_use_certificate_file(sslCtx, certfile, SSL_FILETYPE_PEM)<=0 ){
fossil_fatal("SSL: Unable to open client certificate in %s.", certfile);
}
if( SSL_CTX_use_PrivateKey_file(sslCtx, keyfile, SSL_FILETYPE_PEM)<=0 ){
fossil_fatal("SSL: Unable to open client key in %s.", keyfile);
|
| ︙ | ︙ | |||
389 390 391 392 393 394 395 | /* ** COMMAND: cert ** ** Usage: %fossil cert SUBCOMMAND ... ** | | | | | > | | | < | | | | | | 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
/*
** COMMAND: cert
**
** Usage: %fossil cert SUBCOMMAND ...
**
** Manage/bundle PKI client keys/certificates and CA certificates for SSL
** certificate chain verifications.
**
** %fossil cert add NAME ?--key KEYFILE? ?--cert CERTFILE?
** ?--cafile CAFILE? ?--capath CAPATH?
**
** Create a certificate bundle NAME with the associated
** certificates/keys. If a client certificate is specified but no
** key, it is assumed that the key is located in the client
** certificate file.
** The file formats must be PEM.
**
** %fossil cert list
**
** List all certificate bundles, their values and their URL
** associations.
**
** %fossil cert disassociate URL
**
** Disassociate URL from any certificate bundle.
**
** %fossil cert delete NAME
**
** Remove the certificate bundle NAME and all its URL associations.
**
*/
void cert_cmd(void){
int n;
const char *zCmd = "list"; /* Default sub-command */
if( g.argc>=3 ){
zCmd = g.argv[2];
}
n = strlen(zCmd);
if( strncmp(zCmd, "add", n)==0 ){
const char *zContainer;
const char *zCKey;
const char *zCCert;
const char *zCAFile;
const char *zCAPath;
if( g.argc<5 ){
usage("add NAME ?--key KEYFILE? ?--cert CERTFILE? ?--cafile CAFILE? "
"?--capath CAPATH?");
}
zContainer = g.argv[3];
zCKey = find_option("key",0,1);
zCCert = find_option("cert",0,1);
zCAFile = find_option("cafile",0,1);
zCAPath = find_option("capath",0,1);
/* If a client certificate was specified, but a key was not, assume the
** key is stored in the same file as the certificate.
*/
if( !zCKey && zCCert ){
zCKey = zCCert;
}
db_open_config(0);
db_swap_connections();
create_cert_table_if_not_exist();
db_begin_transaction();
if( db_exists("SELECT 1 FROM certs WHERE name='%q'", zContainer)!=0 ){
db_end_transaction(0);
fossil_fatal("certificate bundle \"%s\" already exists", zContainer);
}
if( zCKey ){
db_multi_exec("INSERT INTO certs (name,type,filepath) "
"VALUES(%Q,'ckey',%Q)",
zContainer, zCKey);
}
if( zCCert ){
|
| ︙ | ︙ | |||
477 478 479 480 481 482 483 |
"VALUES(%Q,'capath',%Q)",
zContainer, zCAPath);
}
db_end_transaction(0);
db_swap_connections();
}else if(strncmp(zCmd, "list", n)==0){
Stmt q;
| | | | | | | | | | | | > | | | 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 |
"VALUES(%Q,'capath',%Q)",
zContainer, zCAPath);
}
db_end_transaction(0);
db_swap_connections();
}else if(strncmp(zCmd, "list", n)==0){
Stmt q;
char *bndl = NULL;
db_open_config(0);
db_swap_connections();
create_cert_table_if_not_exist();
db_prepare(&q, "SELECT name,type,filepath FROM certs"
" WHERE type NOT IN ('server')"
" ORDER BY name,type");
while( db_step(&q)==SQLITE_ROW ){
const char *zCont = db_column_text(&q, 0);
const char *zType = db_column_text(&q, 1);
const char *zFilePath = db_column_text(&q, 2);
if( fossil_strcmp(zCont, bndl)!=0 ){
free(bndl);
bndl = strdup(zCont);
puts(zCont);
}
printf("\t%s=%s\n", zType, zFilePath);
}
db_finalize(&q);
/* List the URL associations. */
db_prepare(&q, "SELECT name FROM global_config"
" WHERE name LIKE 'certbundle:%%' AND value=%Q"
" ORDER BY name", bndl);
free(bndl);
while( db_step(&q)==SQLITE_ROW ){
const char *zName = db_column_text(&q, 0);
static int first = 1;
if( first ) {
puts("\tAssociations");
first = 0;
}
printf("\t\t%s\n", zName+11);
}
db_swap_connections();
}else if(strncmp(zCmd, "disassociate", n)==0){
const char *zURL;
if( g.argc<4 ){
usage("disassociate URL");
}
zURL = g.argv[3];
db_open_config(0);
db_swap_connections();
db_begin_transaction();
db_multi_exec("DELETE FROM global_config WHERE name='certbundle:%q'",
zURL);
if( db_changes() == 0 ){
fossil_warning("No certificate bundle associated with URL \"%s\".",
zURL);
}else{
printf("%s disassociated from its certificate bundle.\n", zURL);
}
db_end_transaction(0);
db_swap_connections();
}else if(strncmp(zCmd, "delete", n)==0){
const char *zContainer;
if( g.argc<4 ){
usage("delete NAME");
}
zContainer = g.argv[3];
db_open_config(0);
db_swap_connections();
create_cert_table_if_not_exist();
db_begin_transaction();
db_multi_exec("DELETE FROM certs WHERE name=%Q", zContainer);
if( db_changes() == 0 ){
fossil_warning("No certificate bundle named \"%s\" found",
zContainer);
}else{
printf("%d entries removed\n", db_changes());
}
db_multi_exec("DELETE FROM global_config WHERE name LIKE 'certbundle:%%'"
" AND value=%Q", zContainer);
if( db_changes() > 0 ){
printf("%d associations removed\n", db_changes());
}
db_end_transaction(0);
db_swap_connections();
}else{
fossil_panic("cert subcommand should be one of: "
"add list disassociate delete");
}
}
|
Changes to src/main.c.
| ︙ | ︙ | |||
100 101 102 103 104 105 106 | char *urlPath; /* Pathname for http: */ char *urlUser; /* User id for http: */ char *urlPasswd; /* Password for http: */ char *urlCanonical; /* Canonical representation of the URL */ char *urlProxyAuth; /* Proxy-Authorizer: string */ char *urlFossil; /* The path of the ?fossil=path suffix on ssh: */ int dontKeepUrl; /* Do not persist the URL */ | | | 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | char *urlPath; /* Pathname for http: */ char *urlUser; /* User id for http: */ char *urlPasswd; /* Password for http: */ char *urlCanonical; /* Canonical representation of the URL */ char *urlProxyAuth; /* Proxy-Authorizer: string */ char *urlFossil; /* The path of the ?fossil=path suffix on ssh: */ int dontKeepUrl; /* Do not persist the URL */ const char *urlCertBundle; /* Which ceritificate bundle to use for URL */ const char *zLogin; /* Login name. "" if not logged in. */ int useLocalauth; /* No login required if from 127.0.0.1 */ int noPswd; /* Logged in without password (on 127.0.0.1) */ int userUid; /* Integer user id */ /* Information used to populate the RCVFROM table */ |
| ︙ | ︙ |
Changes to src/sync.c.
| ︙ | ︙ | |||
94 95 96 97 98 99 100 |
static void process_sync_args(int *pConfigSync, int *pPrivate){
const char *zUrl = 0;
const char *zPw = 0;
int configSync = 0;
int urlOptional = find_option("autourl",0,0)!=0;
g.dontKeepUrl = find_option("once",0,0)!=0;
*pPrivate = find_option("private",0,0)!=0;
| | | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
static void process_sync_args(int *pConfigSync, int *pPrivate){
const char *zUrl = 0;
const char *zPw = 0;
int configSync = 0;
int urlOptional = find_option("autourl",0,0)!=0;
g.dontKeepUrl = find_option("once",0,0)!=0;
*pPrivate = find_option("private",0,0)!=0;
g.urlCertBundle = find_option("certbundle",0,1);
url_proxy_options();
db_find_and_open_repository(0, 0);
db_open_config(0);
if( g.argc==2 ){
zUrl = db_get("last-sync-url", 0);
zPw = unobscure(db_get("last-sync-pw", 0));
if( db_get_boolean("auto-sync",1) ) configSync = CONFIGSET_SHUN;
|
| ︙ | ︙ | |||
149 150 151 152 153 154 155 | ** subsequent push, pull, and sync operations. However, the "--once" ** command-line option makes the URL a one-time-use URL that is not ** saved. ** ** Use the --private option to pull private branches from the ** remote repository. ** | | | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
** subsequent push, pull, and sync operations. However, the "--once"
** command-line option makes the URL a one-time-use URL that is not
** saved.
**
** Use the --private option to pull private branches from the
** remote repository.
**
** Use the "--certbundle NAME" option to specify the name of the
** certificate/key bundle to use for https connections. If this option
** is not specified, a cached value associated with the URL will be
** used if it exists.
**
** See also: cert, clone, push, sync, remote-url
*/
void pull_cmd(void){
|
| ︙ | ︙ | |||
183 184 185 186 187 188 189 | ** subsequent push, pull, and sync operations. However, the "--once" ** command-line option makes the URL a one-time-use URL that is not ** saved. ** ** Use the --private option to push private branches to the ** remote repository. ** | | | 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
** subsequent push, pull, and sync operations. However, the "--once"
** command-line option makes the URL a one-time-use URL that is not
** saved.
**
** Use the --private option to push private branches to the
** remote repository.
**
** Use the "--certbundle NAME" option to specify the name of the
** certificate/key bundle to use for https connections. If this option
** is not specified, a cached value associated with the URL will be
** used if it exists.
**
** See also: cert, clone, pull, sync, remote-url
*/
void push_cmd(void){
|
| ︙ | ︙ | |||
223 224 225 226 227 228 229 | ** subsequent push, pull, and sync operations. However, the "--once" ** command-line option makes the URL a one-time-use URL that is not ** saved. ** ** Use the --private option to sync private branches with the ** remote repository. ** | | | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
** subsequent push, pull, and sync operations. However, the "--once"
** command-line option makes the URL a one-time-use URL that is not
** saved.
**
** Use the --private option to sync private branches with the
** remote repository.
**
** Use the "--certbundle NAME" option to specify the name of the
** certificate/key bundle to use for https connections. If this option
** is not specified, a cached value associated with the URL will be
** used if it exists.
**
** See also: cert, clone, push, pull, remote-url
*/
void sync_cmd(void){
|
| ︙ | ︙ |