OpenSSL
以åãOpenSSLã§Base64å¤æãããã¨ããæã«ããã¡ã¤ã«çµç±ã§ããå¤æã§ããªãã¨ããã£ã¦ããããããã°ã©ã å ã®ã¡ã¢ãªä¸ã§ãå¤æã§ããäºãããã£ãã/docs/man1.0.2/man3/BIO_get_mem_ptr.html c++ - Base64 encoding and decoding with OpenSSL - Stack Oâ¦
HMACã使ã£ã¦ãHMAC-SHA1ãè¨ç®ããã/docs/man1.0.2/crypto/hmac.htmlHMAC.cã§ãkeyã¯"ABC&XYZ" dataã¯"ABCDE" ã¨ãã¦ãããããã®æååã¨é·ããHMACã«æ¸¡ããhmac_sha1ãåºåããå¾ãBase64ã«å¤æãã¦ä½¿ããã¨ãå¤ããããBase64å¤æããæååãåºåãã¦â¦
ãã¡ã¤ã«ã«æååãæ¸ãè¾¼ãå ´åã¯ãBIO_new_file()ã§ãã¡ã¤ã«ç¨ãã¼ã¿ã·ã³ã¯BIOãä½æããã ã¡ã¢ãªã«æååãæ¸ãè¾¼ãã§ããå ´åã¯ãBIO_new()ã«BIO_s_mem()ã渡ããã¨ã§ãã¡ã¢ãªç¨ãã¼ã¿ã·ã³ã¯BIOãä½æããã/docs/man1.0.2/crypto/BIO_s_mem.htmlBIO_s_â¦
BIO_f_base64ã¯Base64ãã£ã«ã¿ã§ãããã使ããã¨ã§Base64ã«å¤æã§ããã/docs/man1.0.2/crypto/BIO_f_base64.htmlBIO_f_base64.cã§ãbufferã¨base64ãbase64ã¨fileãã¨ããå½¢ã§é£çµã $ vi test.txt $ gcc -o BIO_f_base64 BIO_f_base64.c -lcrypto $ ./BIOâ¦
BIO_f_bufferã¯ãããã¡ç¨ãã£ã«ã¿BIOã®ä½æã«ä½¿ããã¨ã¯ç´¹ä»ããã/docs/man1.0.2/crypto/BIO_f_buffer.htmlä»åã¯ãBIO_pushã§é£çµãããããã¡BIOã®bufferã¨ãã¡ã¤ã«BIOã®fileã«ããããæååãæ¸ãè¾¼ãã§ãããBIO_flushã§ãã©ãã·ã¥ã試ããBIO_f_buffâ¦
BIO_pushã§BIOãã§ã¤ã³ãé£çµããã/docs/man1.1.0/crypto/BIO_push.html BIOã¨Base64BIO_push.cãä½æããBIO_pushã§bufferã¨fileãé£çµããã ãã®å¾ãBIO_writeã§bufferã«"ABCDE"ãæ¸ãè¾¼ã¿ãBIO_flushã§ãã©ãã·ã¥ããã¨ãtest.txtã«æ¸ãè¾¼ã¾ããã $ viâ¦
BIO_new_fileã§ãã¡ã¤ã«ç¨ãã¼ã¿ã·ã³ã¯BIOãä½æããã/docs/man1.0.2/crypto/BIO_new_file.htmlBIO_new_file.cã«ãtest.txtãä½æãã¦ããã¦ãBIO_new_file()ã§éãã æ»ãå¤ã®ãã¤ã³ã¿fileãprintfã§åºåã $ vi BIO_new_file.c $ gcc -o BIO_new_file BIOâ¦
BIO_newã§BIOæ§é ä½ã®ãªãã¸ã§ã¯ããä½æã§ããã ä»åã¯ããããã¡ç¨ãã£ã«ã¿BIOãä½æããã/docs/man1.1.0/crypto/BIO_new.htmlBIO_new.cã«ãã¨æ¸ãã BIO_new()ã«BIO_f_buffer()ã®æ»ãå¤ã渡ããã¨ã§ããããã¡ç¨ãã£ã«ã¿BIOãä½æãããbufferã«ãã¤ã³â¦
SHA1_Finalã§çµæãå¾ãã/docs/man1.0.2/crypto/SHA1_Final.htmlSHA1_Final.cã§ãSHA1_Finalã«æ¸¡ããsha1ã«SHA1ããã·ã¥å¤ãæ ¼ç´ãããã $ vi SHA1_Final.c $ gcc -o SHA1_Final SHA1_Final.c -lcrypto $ ./SHA1_Final SHA1_Init success! SHA1_Update sucâ¦
SHA1_Updateã§ãã¼ã¿ã½ã¼ã¹ã追å ããã/docs/man1.0.2/crypto/SHA1_Update.htmlSHA1_Update.cã§ãSHA1_Updateã«strã渡ãã $ vi SHA1_Update.c $ gcc -o SHA1_Update SHA1_Update.c -lcrypto $ ./SHA1_Update SHA1_Init success! SHA1_Update success! $ãâ¦
SHA1ããã·ã¥ã®è¨ç®ãã§ããã SHA1_Initã§åæåã/docs/man1.1.0/crypto/SHA1_Init.htmlSHA1_Init.cã§ãSHA1_Initã«SHA_CTXåsha_ctxã®ã¢ãã¬ã¹ã渡ãã $ vi SHA1_Init.c $ gcc -o SHA1_Init SHA1_Init.c -lcrypto $ ./SHA1_Init SHA1_Init success! $ãâ¦
MD5_Finalã§ãçµæã®ããã·ã¥å¤ãåãåããã/docs/man1.0.2/crypto/MD5_Final.htmlMD5_Final.cã§ãMD5_Finalã«é·ãMD5_DIGEST_LENGTHã®unsigned charåé åmd5ã渡ãã¦ãããã·ã¥å¤ãæ ¼ç´ã md5ã®è¦ç´ ã1ã¤ãã¤foræã§åºåã $ vi MD5_Final.c $ gcc -o MDâ¦
MD5_Updateã§ãã¼ã¿ã½ã¼ã¹(å¤æå ã®æåå)ã渡ãã/docs/man1.0.2/crypto/MD5_Update.htmlMD5_Update.cã§ãMD5_Updateã«æåå"ABCDE"ãæ ¼ç´ããcharåé åstrã渡ã. $ vi MD5_Update.c $ gcc -o MD5_Update MD5_Update.c -lcrypto $ ./MD5_Update MD5_Iniâ¦
OpenSSLã«ã¯ãMD5ããã·ã¥å¤ã®è¨ç®æ©è½ãããã ã¾ãã¯ãMD5_Initã§åæåãmd5_init(3): MD2, MD4, and MD5 hash functions - Linux man pageMD5_Init.cã§ãMD5_Initã«MD5_CTXåmd5_ctxã®ã¢ãã¬ã¹ã渡ãã æ»ãå¤ã1ãªãåæåæåã $ vi MD5_Init.c $ gccâ¦
SSL_readã§ã¬ã¹ãã³ã¹ãèªã¿è¾¼ãã/docs/man1.1.0/ssl/SSL_read.htmlSSL_read.cã§ãSSL_readã§1023ãã¤ããã¤èªã¿è¾¼ãã§ãèªã¿è¾¼ãã ãã¤ããåºåãã¦ããã®ãç¹°ãè¿ãã $ vi SSL_read.c $ gcc -o SSL_read SSL_read.c -lssl -lcrypto $ ./SSL_read connectâ¦
SSL_writeã§ãªã¯ã¨ã¹ãã®æ¸ãè¾¼ã¿ãè¡ãã/docs/man1.1.0/ssl/SSL_write.htmlSSL_write.cã§ãç¨æããGETãªã¯ã¨ã¹ãæååãSSL_writeã§æ¸ãè¾¼ã¿ãæ»ãå¤ã®writtenã«ã¯æ¸ãè¾¼ãããã¤ãæ°ãè¿ãã $ vi SSL_write.c $ gcc -o SSL_write SSL_write.c -lssl -lâ¦
SSL_connectã§ãµã¼ãã¨ã®SSLãã³ãã·ã§ã¤ã¯ãè¡ãã/docs/man1.0.2/ssl/SSL_connect.htmlSSL_connect.cã§ãSSL_connectã«sslã渡ãã¦ãæ»ãå¤ã1ãªãæåã SSLã®åæã«ã¯SSL_shutdownãå¼ã¶ã $ vi SSL_connect.c $ gcc -o SSL_connect SSL_connect.c -lsslâ¦
SSL_set_fdã§ãSSLæ¥ç¶æ å ±ã¨ã½ã±ãããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ãç´ã¥ãããã¨ã§ããã®ã½ã±ããéä¿¡ãSSLéä¿¡ã¨ãããã¨ãã§ãããManual:SSL set fd(3) - OpenSSLWikiSSL_set_fd.cã§ã"www.google.co.jp"ã«ãã¼ã443ã§æ¥ç¶ããã½ã±ããsocãä½æããSSL_set_fâ¦
SSL_newã§ãSSLæ¥ç¶æ å ±ãä½æãããã¨ãã§ããã BIOã使ããªãã§SSLæ¥ç¶ãããå ´åã¯ããã使ãã/docs/man1.0.2/ssl/SSL_new.htmlSSL_new.cã§ãSSL_newã«ctxã渡ããã¨ã§ãsslãä½æã sslã®æãã¢ãã¬ã¹ãåºåã SSL_newã§ä½æããå ´åã¯ãSSL_freeã§sslâ¦
SSL_load_error_stringsãã¨ã©ã¼æååãèªã¿è¾¼ãé¢æ°ã ããERR_load_BIO_stringsã¨ã¯ã¡ãã£ã¨éã模æ§ã/docs/man1.0.2/crypto/SSL_load_error_strings.htmlSSL_load_error_strings.cã§ãERR_load_BIO_stringsã«å ãã¦ãSSL_load_error_stringsãå¼ã¶ã $ vâ¦
ERR_load_BIO_stringsã§ãã¨ã©ã¼æååããã¼ããããã¨ã§ãæå³ã®åãããªãã¨ã©ã¼ã³ã¼ããããç¨åº¦ã¨ã©ã¼æååã«å¤æãã¦åºåããããOpenSSL API ã«ããã»ãã¥ã¢ã»ããã°ã©ãã³ã°: 第 1 å API ã®æ¦è¦ERR_load_BIO_strings.cã§ãæåã«ERR_load_BIO_striâ¦
ERR_print_errors_fpã«ãã¡ã¤ã«ãã¤ã³ã¿ãæå®ããã¨ããã®ã¹ããªã¼ã ã«OpenSSLã®ã¨ã©ã¼ã¡ãã»ã¼ã¸ãæ¸ãè¾¼ãã/docs/man1.1.0/crypto/ERR_print_errors_fp.htmlERR_print_errors_fp.cã§ãSSL_CTX_load_verify_locationsã§"dummyurl"ã¨ããåå¨ããªããã¹ãâ¦
SSL_get_verify_resultã§ãæ¥ç¶å ã®SSL証ææ¸ã®æ¤è¨¼çµæãåå¾ããã ããã§åé¡ãªããªãã°ããªã¯ã¨ã¹ãã®æ¸ãè¾¼ã¿ãããã¨ããæµãã¨ãªãã/docs/man1.0.2/ssl/SSL_get_verify_result.htmlSSL_get_verify_result.cã§ãBIO_do_connectã§æ¥ç¶å¾ãSSL_get_veriâ¦
éã»ãã¥ã¢ãªå ´åã¯ãBIO_new_connectã§æ¥ç¶å ãã¹ãåã¨ãã¼ããæå®ãã¦ããããã»ãã¥ã¢ãªå ´åã«ãBIO_new_ssl_connectã«ã¯SSL_CTXåãã¤ã³ã¿ãã渡ããªããããBIO_set_conn_hostnameã使ããbio_set_conn_hostname(3): connect BIO - Linux man pageBIOâ¦
SSL_set_modeã§SSLã¢ã¼ããè¨å®ããã/docs/man1.1.0/ssl/SSL_get_mode.htmlSSL_set_mode.cã§ãSSL_get_modeã§ãªã«ãã»ããããã¦ããªããã¨ã確èªãã¦ãããSSL_set_modeã§SSL_MODE_AUTO_RETRYãã»ããããã SSL_get_modeãåã³å¼ãã§ãssl_modeã«SSL_MODEâ¦
SSL_get_modeã§ãç¾å¨ã®SSLã¢ã¼ããåå¾ã§ããã/docs/man1.0.2/ssl/SSL_get_mode.htmlSSL_get_mode.cã§ãSSL_get_modeã«sslã渡ãã¨ãlongåå¤æ°ssl_modeã«SSLã¢ã¼ãã®å¤ãè¿ã£ã¦ããã $ vi SSL_get_mode.c $ gcc -o SSL_get_mode SSL_get_mode.c -lssl -lâ¦
BIOæ§é ä½ãã¤ã³ã¿ã®bioãããä»åº¦ã¯SSLæ¥ç¶æ å ±ãæã¤SSLæ§é ä½ãã¤ã³ã¿ã®sslãåå¾ããã ããã«ã¯BIO_get_sslã使ããbio_get_ssl(3): SSL BIO - Linux man pageBIO_get_ssl.cã§ãBIO_get_sslã®ç¬¬1å¼æ°ã«bioã渡ãã第2å¼æ°ã«sslã®ã¢ãã¬ã¹ã渡ãã¨ãsslâ¦
SSLã®å ´åã¯ãBIO_new_ssl_connectã§ã³ãã¯ã·ã§ã³ä½æããããbio_new_ssl_connect(3): SSL BIO - Linux man pageBIO_new_ssl_connect.cã§ãBIO_new_ssl_connectã«ctxã渡ãã¦bioãåãåã£ã¦ãbioãåºåã çµãã£ããBIO_free_allã§è§£æ¾ã $ vi BIO_new_sslâ¦
ã»ãã¥ã¢ãªæ¥ç¶ãããã«ã¯ãSSL_CTX_load_verify_locationsã§ãä¿¡é ¼ã§ãã証ææ¸ã¹ãã¢ããã¼ãããå¿ è¦ãããã/docs/man1.0.2/ssl/SSL_CTX_load_verify_locations.htmlSSL_CTX_load_verify_locations.cã§ãSSL_CTX_load_verify_locationsã«SSLã³ã³ããã¹ãâ¦
ä»åº¦ã¯ã»ãã¥ã¢ãªæ¥ç¶ããã¦ãããã¨ãããã ã¾ãã¯ãSSLæ å ±ãæã¤SSLã³ã³ããã¹ããä½æããã SSLã³ã³ããã¹ãã¯SSL_CTX_newã§ä½æããã/docs/man1.0.2/ssl/SSL_CTX_new.htmlSSL_CTX_new.cã§ãSSL_CTXåãã¤ã³ã¿ctxãç¨æãSSL_library_initã§åæåãâ¦