Changeset 3106 for pjproject/trunk/pjlib/src/pj/ssl_sock_symbian.cpp
- Timestamp:
- Feb 24, 2010 5:43:34 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/ssl_sock_symbian.cpp
r2998 r3106 128 128 return KErrNotFound; 129 129 } 130 const CX509Certificate *GetPeerCert() { 131 if (securesock_) 132 return securesock_->ServerCert(); 133 return NULL; 134 } 130 135 131 136 private: … … 410 415 struct pj_ssl_sock_t 411 416 { 417 pj_pool_t *pool; 412 418 pj_ssl_sock_cb cb; 413 419 void *user_data; … … 435 441 pj_ssl_cipher *ciphers; 436 442 pj_str_t servername; 443 pj_ssl_cert_info remote_cert_info; 437 444 }; 445 446 447 static pj_str_t get_cert_name(pj_pool_t *pool, 448 const CX500DistinguishedName &name) 449 { 450 TInt i; 451 char buf[1024]; 452 TUint8 *p; 453 TInt l = sizeof(buf); 454 455 p = (TUint8*)buf; 456 for(i = 0; i < name.Count(); ++i) { 457 const CX520AttributeTypeAndValue &attr = name.Element(i); 458 459 /* Print element separator */ 460 *p++ = '/'; 461 if (0 == --l) break; 462 463 /* Print the type. */ 464 TPtr8 type(p, l); 465 type.Copy(attr.Type()); 466 p += type.Length(); 467 l -= type.Length(); 468 if (0 >= --l) break; 469 470 /* Print equal sign */ 471 *p++ = '='; 472 if (0 == --l) break; 473 474 /* Print the value. Let's just get the raw data here */ 475 TPtr8 value(p, l); 476 value.Copy(attr.EncodedValue().Mid(2)); 477 p += value.Length(); 478 l -= value.Length(); 479 if (0 >= --l) break; 480 } 481 482 pj_str_t src, res; 483 pj_strset(&src, buf, sizeof(buf) - l); 484 pj_strdup(pool, &res, &src); 485 486 return res; 487 } 488 489 /* Get certificate info from CX509Certificate. 490 */ 491 static void get_cert_info(pj_pool_t *pool, pj_ssl_cert_info *ci, 492 const CX509Certificate *x) 493 { 494 unsigned len; 495 496 pj_assert(pool && ci && x); 497 498 pj_bzero(ci, sizeof(*ci)); 499 500 /* Version */ 501 ci->version = x->Version(); 502 503 /* Serial number */ 504 len = x->SerialNumber().Length(); 505 if (len > sizeof(ci->serial_no)) 506 len = sizeof(ci->serial_no); 507 pj_memcpy(ci->serial_no + sizeof(ci->serial_no) - len, 508 x->SerialNumber().Ptr(), len); 509 510 /* Subject */ 511 { 512 HBufC *subject = NULL; 513 TRAPD(err, subject = x->SubjectL()); 514 if (err == KErrNone) { 515 TPtr16 ptr16(subject->Des()); 516 len = ptr16.Length(); 517 TPtr8 ptr8((TUint8*)pj_pool_alloc(pool, len), len); 518 ptr8.Copy(ptr16); 519 pj_strset(&ci->subject.cn, (char*)ptr8.Ptr(), ptr8.Length()); 520 } 521 ci->subject.info = get_cert_name(pool, x->SubjectName()); 522 } 523 524 /* Issuer */ 525 { 526 HBufC *issuer = NULL; 527 TRAPD(err, issuer = x->IssuerL()); 528 if (err == KErrNone) { 529 TPtr16 ptr16(issuer->Des()); 530 len = ptr16.Length(); 531 TPtr8 ptr8((TUint8*)pj_pool_alloc(pool, len), len); 532 ptr8.Copy(ptr16); 533 pj_strset(&ci->issuer.cn, (char*)ptr8.Ptr(), ptr8.Length()); 534 } 535 ci->issuer.info = get_cert_name(pool, x->IssuerName()); 536 } 537 538 /* Validity */ 539 const CValidityPeriod &valid_period = x->ValidityPeriod(); 540 TTime base_time(TDateTime(1970, EJanuary, 0, 0, 0, 0, 0)); 541 TTimeIntervalSeconds tmp_sec; 542 valid_period.Start().SecondsFrom(base_time, tmp_sec); 543 ci->validity.start.sec = tmp_sec.Int(); 544 valid_period.Finish().SecondsFrom(base_time, tmp_sec); 545 ci->validity.end.sec = tmp_sec.Int(); 546 } 547 548 549 /* Update certificates info. This function should be called after handshake 550 * or renegotiation successfully completed. 551 */ 552 static void update_certs_info(pj_ssl_sock_t *ssock) 553 { 554 const CX509Certificate *x; 555 556 pj_assert(ssock && ssock->sock && 557 ssock->sock->GetState() == CPjSSLSocket::SSL_STATE_ESTABLISHED); 558 559 /* Active remote certificate */ 560 x = ssock->sock->GetPeerCert(); 561 if (x) { 562 get_cert_info(ssock->pool, &ssock->remote_cert_info, x); 563 } else { 564 pj_bzero(&ssock->remote_cert_info, sizeof(pj_ssl_cert_info)); 565 } 566 } 438 567 439 568 … … 505 634 506 635 /* Init secure socket */ 636 ssock->pool = pool; 507 637 ssock->sock_af = param->sock_af; 508 638 ssock->sock_type = param->sock_type; … … 644 774 /* Remote address */ 645 775 pj_sockaddr_cp((pj_sockaddr_t*)&info->remote_addr, 646 (pj_sockaddr_t*)&ssock->rem_addr); 776 (pj_sockaddr_t*)&ssock->rem_addr); 777 778 /* Certificates info */ 779 info->remote_cert_info = &ssock->remote_cert_info; 647 780 } 648 781 … … 729 862 status = reader->Read(&read_cb, ssock, *ssock->read_state.read_buf, 730 863 ssock->read_state.flags); 731 if (status != PJ_EPENDING) { 732 /* Notify error */ 733 (*ssock->cb.on_data_read)(ssock, NULL, 0, status, NULL); 734 } 735 } 736 864 } 865 866 /* Connection closed or something goes wrong */ 737 867 if (status != PJ_SUCCESS && status != PJ_EPENDING) { 738 /* Connection closed or something goes wrong */ 868 /* Notify error */ 869 if (ssock->cb.on_data_read) { 870 pj_bool_t ret = (*ssock->cb.on_data_read)(ssock, NULL, 0, 871 status, NULL); 872 if (!ret) { 873 /* We've been destroyed */ 874 return; 875 } 876 } 877 739 878 delete ssock->read_state.read_buf; 740 879 delete ssock->read_state.orig_buf; … … 1002 1141 if (status == PJ_SUCCESS) { 1003 1142 ssock->established = PJ_TRUE; 1143 update_certs_info(ssock); 1004 1144 } else { 1005 1145 delete ssock->sock;
Note: See TracChangeset
for help on using the changeset viewer.