-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jianhui Zhao <[email protected]>
- Loading branch information
Showing
8 changed files
with
212 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDbzCCAlegAwIBAgIUdHJODTH4Ym0AAUyM54BqJBQZNIAwDQYJKoZIhvcNAQEL | ||
BQAwRzELMAkGA1UEBhMCQ1oxEjAQBgNVBAoMCUFjbWUgSW5jLjENMAsGA1UECwwE | ||
QUNNRTEVMBMGA1UEAwwMQUNNRS1ERVYtMTIzMB4XDTIyMDQyOTE1NDUzN1oXDTIy | ||
MDUyOTE1NDUzN1owRzELMAkGA1UEBhMCQ1oxEjAQBgNVBAoMCUFjbWUgSW5jLjEN | ||
MAsGA1UECwwEQUNNRTEVMBMGA1UEAwwMQUNNRS1ERVYtMTIzMIIBIjANBgkqhkiG | ||
9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6udad6dBQwX1GW2z+7yPX7Aq8Rkoi7BFIdmQ | ||
px3w/5t35FQtE+O/+4GsIPXIXEq0Q0vezZRCkRe8Jdona5blqZv8s2tP2rPoI3Sk | ||
YE/0kAvAMA18Xh4VyGw5xlFIrOa9T1yAhAD3xGD33kS/mhJEDnLn9GCQ7nEwoxoJ | ||
XEZf8/7B0+GxLfoR2VpO+gZNWtsCHYidIY6QU3YvgcvGb2RAKULCQAoY86CKleBd | ||
WO3nVKNOCv1mb1WrqKiUC6kmFACeau6gLywyJXGej8M3+YuozxDirwAHiuFKZItX | ||
CGoaMwZrGBouSCq4T4UJiIjZPaSCRY0B0bB1WDuXSK+JqHFDJQIDAQABo1MwUTAd | ||
BgNVHQ4EFgQU/KbZRAdXeskytl6tj0Gw0kjXVZcwHwYDVR0jBBgwFoAU/KbZRAdX | ||
eskytl6tj0Gw0kjXVZcwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOC | ||
AQEAFknK2HoE86Yxf29mux2MltkBvLsUIgliCVanPUiJOFOjoLPzLnpmyJcTnpdG | ||
W+d9GqLzxfbmtVPI0YzB8uYV2r/Xh3LN5H+UB9v/5IjQcFftTIj3oECGEOQOEu75 | ||
M1o4d/moazbZCauZi63N3GlgdQmIsuAoQy6wy3j8AkxQGt2ptASffx0rDXjS7Z+L | ||
XM3RN0/d/h3iAwboeT5XhUVkEa2zSOw0NmXTCKpNJvPr0ulLLCpSOErD6Jq+sMw5 | ||
En+VZhh4QiK7eqqb/tuQclkcGxcSAIRpVg98+PLnwi0VYR2YPnwxV1SAqMDWKHYH | ||
U3X0GiiOs125w7x4zFV9d+73/Q== | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#ifndef __EXAMPLE_H | ||
#define __EXAMPLE_H | ||
|
||
#include <sys/select.h> | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
|
||
#include "ssl.h" | ||
|
||
static int ssl_select(int sock, int ret) | ||
{ | ||
fd_set fds = {}; | ||
|
||
FD_SET(sock, &fds); | ||
|
||
if (ret == SSL_WANT_READ) | ||
ret = select(sock + 1, &fds, NULL, NULL, NULL); | ||
else if (ret == SSL_WANT_WRITE) | ||
ret = select(sock + 1, NULL, &fds, NULL, NULL); | ||
|
||
if (ret < 0) { | ||
perror("select"); | ||
return -1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static void on_verify_error(int error, const char *str, void *arg) | ||
{ | ||
fprintf(stderr, "WARNING: SSL certificate error(%d): %s\n", error, str); | ||
} | ||
|
||
static int ssl_write_nonblock(void *ssl, int sock, void *data, int len) | ||
{ | ||
char err_buf[128]; | ||
fd_set fds; | ||
int ret; | ||
|
||
while (true) { | ||
ret = ssl_write(ssl, data, len); | ||
if (ret == SSL_ERROR) { | ||
fprintf(stderr, "ssl_write: %s\n", ssl_last_error_string(err_buf, sizeof(err_buf))); | ||
return -1; | ||
} | ||
|
||
if (ret > 0) | ||
return ret; | ||
|
||
if (ssl_select(sock, ret)) | ||
return -1; | ||
} | ||
} | ||
|
||
static int ssl_read_nonblock(void *ssl, int sock, void *data, int len, bool *closed) | ||
{ | ||
char err_buf[128]; | ||
fd_set fds; | ||
int ret; | ||
|
||
*closed = false; | ||
|
||
while (true) { | ||
ret = ssl_read(ssl, data, len); | ||
if (ret == SSL_ERROR) { | ||
fprintf(stderr, "ssl_read: %s\n", ssl_last_error_string(err_buf, sizeof(err_buf))); | ||
return -1; | ||
} | ||
|
||
if (ret > 0) | ||
return ret; | ||
|
||
if (ret == 0) { | ||
*closed = true; | ||
return 0; | ||
} | ||
|
||
if (ret == SSL_WANT_READ) | ||
return 0; | ||
|
||
if (ssl_select(sock, ret)) | ||
return -1; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDq51p3p0FDBfUZ | ||
bbP7vI9fsCrxGSiLsEUh2ZCnHfD/m3fkVC0T47/7gawg9chcSrRDS97NlEKRF7wl | ||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BpiX45S55Y | ||
Do0q0M9uXNU7BoWhJhz9iJKa4uV8la7BKUFb/XDeLYyd9xcVPqCPi3OW/+lr4DvR | ||
jKbWIoT2Z4YVNoJ6uQjmghbk7zwGK4XECGxocwfUKVz3/2Nhrydwl6J3AoGAPN4f | ||
rsS7U/9La+SqZgYZzyH/4YnDtGRpW0gwlibwusACqfxVX4+d/JGpMR6L/dYVZrzv | ||
1svo9Bq+sF5H228/2CcKSzNzSeTTxp/TgyWXGjj/4lM9Xp225bLOObHgLD++Yt7p | ||
LJ2owHK2d8+RLtR8OInszrYn/UvrHgKX0SeHI0UCgYEA7YM/WpeB24Wlt2viujEi | ||
EcBx5BLu+uoere7Q9veCXXvbUYm46nkAU0tf2BolGtmDTMdPPf8sVLfwS4xUQiXq | ||
nbe5SHBUHzB/js8FQtnud4SkDB1I/93XoxHsX20quwISQEi146ezTxBdTzC3wDvM | ||
OkkCScqCD+xXUwi1dsbXr3g= | ||
-----END PRIVATE KEY----- |
Oops, something went wrong.