码迷,mamicode.com
首页 > 其他好文 > 详细

不使用PEM 文件建立SSL通道

时间:2020-07-03 19:35:06      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:ann   nop   smp   gpe   taf   mod   new   log   pat   

  1 
  2 static unsigned char public_pem[]="-----BEGIN CERTIFICATE-----\n"
  3     "MIIDazCCAlOgAwIBAgIUEk+7+NYeiinQ6EwHUC878nYvrxswDQYJKoZIhvcNAQEL\n"
  4     "BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM\n"
  5     "GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMDA2MTcwNzA1NThaFw0yMzA2\n"
  6     "MTcwNzA1NThaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw\n"
  7     "HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggEiMA0GCSqGSIb3DQEB\n"
  8     "AQUAA4IBDwAwggEKAoIBAQC8eer+gOcrcIx+47sEakT97kM4xGBpEGDNuc79YpnT\n"
  9     "LbKPfH2UnCAN6mOR6RLGXytrpwtSO54LLQ6CW0mapNQZLcYc5HltcyFM+revsybx\n"
 10     "ju39uJZ1tTGvKgPuHc8jmHiCDzX/uqqJTV9A6+S4jdrre42X6pAtMK7aRdjWuRY3\n"
 11     "Y5N78bR3pIwPo5phSVvU7SnYU6LbZ20oPq0sQMms6gfIDVTY8Oea2ryD/CI/wm4L\n"
 12     "Zjsic3QBmLwu7dEj8OoglK/SY4M5JToy0xiA9JVZ1O/qO5x+DlP0I5s/yUGGYmrh\n"
 13     "w7cCUuE/Eeb0U4Hy2RPVsWzZcyYLIlsZ/wVoNHUat4YxAgMBAAGjUzBRMB0GA1Ud\n"
 14     "DgQWBBQCYXVLBTHKI6bQdZsF3wPAi/OCxzAfBgNVHSMEGDAWgBQCYXVLBTHKI6bQ\n"
 15     "dZsF3wPAi/OCxzAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAJ\n"
 16     "AEjziL3NdqlmeQcC3ZmfDYgDt8qUKrNtQBhvOu9/le1lcFOOpNag7WoLFR2Yktm3\n"
 17     "Mea6H9PhsldL0cOQPoe0HpkUyXWBEip0pthNwBQzGU5FAL4TP7MhSQROBtLJf31s\n"
 18     "jaIVh8+CsM0TE3jbv2w1b4+tARFoJitUic71eOEWhgJ+Fm0yGAlUhmIHPx5SzehG\n"
 19     "waDrfaSp6gWRNO+5W0Y55RVCuEMSmPt783vVum5f+rkdhaowYGTW6FvmXoAdP/a1\n"
 20     "Ryl3ighzGfrgiAHpfftj1u1HCmFvMHgdt16/wSmoHRo0vKSv+/hKNAhr+USsyXaw\n"
 21     "KHU3w4paqT+ph/8uKPI1\n"
 22     "-----END CERTIFICATE-----\n"
 23     ;
 24 
 25 
 26 static unsigned char private_pem[]="-----BEGIN RSA PRIVATE KEY-----\n"
 27     "MIIEowIBAAKCAQEAvHnq/oDnK3CMfuO7BGpE/e5DOMRgaRBgzbnO/WKZ0y2yj3x9\n"
 28     "lJwgDepjkekSxl8ra6cLUjueCy0OgltJmqTUGS3GHOR5bXMhTPq3r7Mm8Y7t/biW\n"
 29     "dbUxryoD7h3PI5h4gg81/7qqiU1fQOvkuI3a63uNl+qQLTCu2kXY1rkWN2OTe/G0\n"
 30     "d6SMD6OaYUlb1O0p2FOi22dtKD6tLEDJrOoHyA1U2PDnmtq8g/wiP8JuC2Y7InN0\n"
 31     "AZi8Lu3RI/DqIJSv0mODOSU6MtMYgPSVWdTv6jucfg5T9CObP8lBhmJq4cO3AlLh\n"
 32     "PxHm9FOB8tkT1bFs2XMmCyJbGf8FaDR1GreGMQIDAQABAoIBADEYFNUsYIrZK0+W\n"
 33     "JE3XHJeEa7Aqvu4/HOgZoUgxWd4/RgbIJ7IBJPxa9Iq6SnCvs5C8F1/ZNaa1mtTr\n"
 34     "0HVev/y7BqLaBKM03RS/Lf+vS9KaJ3XykgahJwr4h8OLsjwUaDeAnNE7H1bad5hi\n"
 35     "mdZU5RR3v381005iIvmqPfxYg+fzLi7bWWoBH063Wsrx8paznTv1hpeDkF4Xt4n3\n"
 36     "2wktEasxdobmzodJ5gMJoBpVEQ+KRBCrKimCxyt3ZjWlRNC3iTa9mKlAQMBdGNqk\n"
 37     "OkiUvLCzVNMcndHCCe42Bo5xqxDq9P70aLgFQzf0jWghzoYlpZjqqehqLdWvqzQT\n"
 38     "eHgXjc0CgYEA8b0IBNoQv/Gion6Sj8E3cF2Zj82Gg/3sBkRBxZwwyeXCwa3MASOr\n"
 39     "RV1d/kD6J8Crjp1pGwGsqeA099LzvVKXfZ0jx8CR3bJ3wwgwOn+i2kj1GCott6DG\n"
 40     "58t5+hVijoFJITLkEY0zcvS2gtnDL/EIbPdBNk4oRTynJhqKquycizMCgYEAx5h4\n"
 41     "OIKuXawz5xmxqRTFhDgluU0o/9CRwvBX1pitcSrAPTwhPBenPEqwY4y71js0B212\n"
 42     "hInbp80GxiK0G03mu50s5/O17XIB9+Jp+VW/vAVrcdSod0eIQS36a0pOUDLcLoSQ\n"
 43     "17JCVtPfcG3PkC9mC539DCt3sJUVhApV0WKESQsCgYEA672jX0/lO7oCFyMF/Gi5\n"
 44     "jrvIsEMGphtvG6Fe3r31mj6VEdlR8957/LYTnopxKWksJHT/ddXJMxSxsugmx/8O\n"
 45     "OvKOXRM/bIrJXgnTNokYIHU7hyhC0ytYLd3xgt9t8HjF/zkozrD7dmSMw8hnH46X\n"
 46     "3+Oz1aicfwCqJG+HwS3jb58CgYAixVwENDfeF7a/Bsndc8HpA8MGofuHfTU3aZlT\n"
 47     "yCtG8LSmtkfv6Qr4ROavoP/EFXI97QLdmgqLE/ufHsKTkyGkA4CkM9+4qsjO/0GI\n"
 48     "7zhEsAkEvpBOn0aMXE8oy7wS2pli/TMicGqAJ87gDjE/pBI56d8AdL4YJBCofQhw\n"
 49     "PqJe+wKBgHPpbMNxYofSIf9vkaE/ukg00DFrNO7MX7Q6FOQG3omUQ9456hRtySvA\n"
 50     "PuuuwX7qWnoiauwJ+G4Gs+7lX9MMGjhlpHX2qPnb8YvliFXuoDqG7XwCtLmhXM3a\n"
 51     "0ycSMi0AYO6qQ5F2kIcHewOrghdK5PsT7Xj22ZmkS8/o3WdV6h1B\n"
 52     "-----END RSA PRIVATE KEY-----\n";
 53 
 54 
 55 EVP_PKEY *pEvp_pkey = NULL;
 56     X509 *pX509 = NULL;
 57 
 58     BIO *publicbio = BIO_new_mem_buf (public_pem, -1);
 59     assert (publicbio);
 60     PEM_read_bio_X509 (publicbio, &pX509, NULL, 0);
 61     BIO_free (publicbio);
 62 
 63     BIO *privatebio = BIO_new_mem_buf (private_pem, -1);
 64     assert (privatebio);
 65     PEM_read_bio_PrivateKey (privatebio, &pEvp_pkey, 0, 0);
 66     BIO_free (privatebio);
 67 
 68     int e;
 69     e = SSL_CTX_use_certificate (ctx, pX509);
 70     if (e <= 0) ERR_print_errors_fp(stderr);
 71     assert (e > 0);
 72 
 73     e = SSL_CTX_use_PrivateKey (ctx, pEvp_pkey);
 74     if (e <= 0) ERR_print_errors_fp(stderr);
 75     assert (e > 0);

不使用PEM 文件建立SSL通道

标签:ann   nop   smp   gpe   taf   mod   new   log   pat   

原文地址:https://www.cnblogs.com/thinkinc999/p/13232084.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!