{"id":7385,"date":"2022-12-20T19:37:54","date_gmt":"2022-12-20T22:37:54","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/iosocketsslutils-man3\/"},"modified":"2022-12-20T19:37:54","modified_gmt":"2022-12-20T22:37:54","slug":"iosocketsslutils-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/iosocketsslutils-man3\/","title":{"rendered":"IO::Socket::SSL::Utils (man3)"},"content":{"rendered":"<h1 align=\"center\">IO::Socket::SSL::Utils<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#FUNCTIONS\">FUNCTIONS<\/a><br \/> <a href=\"#AUTHOR\">AUTHOR<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">IO::Socket::SSL::Utils \u2212\u2212 loading, storing, creating certificates and keys<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">use IO::Socket::SSL::Utils; <br \/> my $cert = PEM_file2cert(&#8216;cert.pem&#8217;); # load certificate from file <br \/> my $string = PEM_cert2string($cert); # convert certificate to PEM string <br \/> CERT_free($cert); # free memory within OpenSSL <br \/> my $key = KEY_create_rsa(2048); # create new 2048\u2212bit RSA key <br \/> PEM_string2file($key,&#8221;key.pem&#8221;); # and write it to file <br \/> KEY_free($key); # free memory within OpenSSL<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This module provides various utility functions to work with certificates and private keys, shielding some of the complexity of the underlying Net::SSLeay and OpenSSL.<\/p>\n<h2>FUNCTIONS <a name=\"FUNCTIONS\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"83%\">\n<p style=\"margin-top: 1em\">Functions converting between string or file and certificates and keys. They croak if the operation cannot be completed.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\">PEM_file2cert(file) \u2212> cert <br \/> PEM_cert2file(cert,file) <br \/> PEM_string2cert(string) \u2212> cert <br \/> PEM_cert2string(cert) \u2212> string <br \/> PEM_file2key(file) \u2212> key <br \/> PEM_key2file(key,file) <br \/> PEM_string2key(string) \u2212> key <br \/> PEM_key2string(key) \u2212> string<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"83%\">\n<p>Functions for cleaning up. Each loaded or created cert and key must be freed to not leak memory.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\">CERT_free(cert) <br \/> KEY_free(key)<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"41%\">\n<p>KEY_create_rsa(bits) \u2212> key<\/p>\n<\/td>\n<td width=\"42%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%; margin-top: 1em\">Creates an <small>RSA<\/small> key pair, bits defaults to 2048.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"41%\">\n<p style=\"margin-top: 1em\">KEY_create_ec(curve) \u2212> key<\/p>\n<\/td>\n<td width=\"42%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%; margin-top: 1em\">Creates an <small>EC<\/small> key, curve defaults to &#8220;prime256v1&#8221;.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"60%\">\n<p style=\"margin-top: 1em\">CERT_asHash(cert,[digest_algo]) \u2212> hash<\/p>\n<\/td>\n<td width=\"23%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%; margin-top: 1em\">Extracts the information from the certificate into a hash and uses the given digest_algo (default: <small>SHA\u2212256<\/small> ) to determine digest of pubkey and cert. The resulting hash contains:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"11%\">\n<p style=\"margin-top: 1em\">subject<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"71%\">\n<p style=\"margin-top: 1em\">Hash with the parts of the subject, e.g. commonName, countryName, organizationName, stateOrProvinceName, localityName.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\">subjectAltNames<\/p>\n<p style=\"margin-left:29%;\">Array with list of alternative names. Each entry in the list is of &#8220;[type,value]&#8221;, where &#8220;type&#8221; can be <small>OTHERNAME, EMAIL, DNS, X400, DIRNAME, EDIPARTY, URI, IP<\/small> or <small>RID.<\/small><\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"9%\">\n<p>issuer<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"71%\">\n<p>Hash with the parts of the issuer, e.g. commonName, countryName, organizationName, stateOrProvinceName, localityName.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\">not_before, not_after<\/p>\n<p style=\"margin-left:29%;\">The time frame, where the certificate is valid, as time_t, e.g. can be converted with localtime or similar functions.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"11%\">\n<p>serial<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"53%\">\n<p>The serial number<\/p>\n<\/td>\n<td width=\"18%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"11%\">\n<p>crl_uri<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"53%\">\n<p>List of URIs for <small>CRL<\/small> distribution.<\/p>\n<\/td>\n<td width=\"18%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\">ocsp_uri<\/p>\n<p style=\"margin-left:29%;\">List of URIs for revocation checking using <small>OCSP.<\/small><\/p>\n<p style=\"margin-left:17%;\">keyusage<\/p>\n<p style=\"margin-left:29%;\">List of keyUsage information in the certificate.<\/p>\n<p style=\"margin-left:17%;\">extkeyusage<\/p>\n<p style=\"margin-left:29%;\">List of extended key usage information from the certificate. Each entry in this list consists of a hash with oid, nid, ln and sn.<\/p>\n<p style=\"margin-left:17%;\">pubkey_digest_xxx<\/p>\n<p style=\"margin-left:29%;\">Binary digest of the pubkey using the given digest algorithm, e.g. pubkey_digest_sha256 if (the default) <small>SHA\u2212256<\/small> was used.<\/p>\n<p style=\"margin-left:17%;\">x509_digest_xxx<\/p>\n<p style=\"margin-left:29%;\">Binary digest of the X.509 certificate using the given digest algorithm, e.g. x509_digest_sha256 if (the default) <small>SHA\u2212256<\/small> was used.<\/p>\n<p style=\"margin-left:17%;\">fingerprint_xxx<\/p>\n<p style=\"margin-left:29%;\">Fingerprint of the certificate using the given digest algorithm, e.g. fingerprint_sha256 if (the default) <small>SHA\u2212256<\/small> was used. Contrary to digest_* this is an <small>ASCII<\/small> string with a list if hexadecimal numbers, e.g. &#8220;73:59:75:5C:6D&#8230;&#8221;.<\/p>\n<p style=\"margin-left:17%;\">signature_alg<\/p>\n<p style=\"margin-left:29%;\">Algorithm used to sign certificate, e.g. &#8220;sha256WithRSAEncryption&#8221;.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"17%\">\n<p>ext<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"71%\">\n<p>List of extensions. Each entry in the list is a hash with oid, nid, sn, critical flag (boolean) and data (string representation given by X509V3_EXT_print).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"17%\">\n<p>version<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"71%\">\n<p>Certificate version, usually 2 (x509v3)<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"17%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"71%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%; margin-top: 1em\">CERT_create(hash) \u2212> (cert,key)<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">Creates a certificate based on the given hash. If the issuer is not specified the certificate will be self-signed. The following keys can be given:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"11%\">\n<p style=\"margin-top: 1em\">subject<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"71%\">\n<p style=\"margin-top: 1em\">Hash with the parts of the subject, e.g. commonName, countryName, &#8230; as described in &#8220;CERT_asHash&#8221;. Default points to IO::Socket::SSL.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\">not_before<\/p>\n<p style=\"margin-left:29%;\">A time_t value when the certificate starts to be valid. Defaults to current time.<\/p>\n<p style=\"margin-left:17%;\">not_after<\/p>\n<p style=\"margin-left:29%;\">A time_t value when the certificate ends to be valid. Defaults to current time plus one 365 days.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"11%\">\n<p>serial<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"71%\">\n<p>The serial number. If not given a random number will be used.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"11%\">\n<p>version<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"71%\">\n<p>The version of the certificate, default 2 (x509v3).<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\"><small>CA<\/small> true|false<\/p>\n<p style=\"margin-left:29%;\">If true declare certificate as <small>CA,<\/small> defaults to false.<\/p>\n<p style=\"margin-left:17%;\">purpose string|array|hash<\/p>\n<p style=\"margin-left:29%;\">Set the purpose of the certificate. The different purposes can be given as a string separated by non-word character, as array or hash. With string or array each purpose can be prefixed with \u2019+\u2019 (enable) or \u2019\u2212\u2019 (disable) and same can be done with the value when given as a hash. By default enabling the purpose is assumed.<\/p>\n<p style=\"margin-left:29%; margin-top: 1em\">If the <small>CA<\/small> option is given and true the defaults &#8220;ca,sslca,emailca,objca&#8221; are assumed, but can be overridden with explicit purpose. If the <small>CA<\/small> option is given and false the defaults &#8220;server,client&#8221; are assumed. If no <small>CA<\/small> option and no purpose is given it defaults to &#8220;server,client&#8221;.<\/p>\n<p style=\"margin-left:29%; margin-top: 1em\">Purpose affects basicConstraints, keyUsage, extKeyUsage and netscapeCertType. The following purposes are defined (case is not important):<\/p>\n<p style=\"margin-left:29%; margin-top: 1em\">client <br \/> server <br \/> email <br \/> objsign <br \/> CA <br \/> sslCA <br \/> emailCA <br \/> objCA <br \/> emailProtection <br \/> codeSigning <br \/> timeStamping <br \/> digitalSignature <br \/> nonRepudiation <br \/> keyEncipherment <br \/> dataEncipherment <br \/> keyAgreement <br \/> keyCertSign <br \/> cRLSign <br \/> encipherOnly <br \/> decipherOnly<\/p>\n<p style=\"margin-left:29%; margin-top: 1em\">Examples:<\/p>\n<p style=\"margin-left:29%; margin-top: 1em\"># root\u2212CA for SSL certificates <br \/> purpose => &#8216;sslCA&#8217; # or CA => 1 <br \/> # server certificate and CA (typically self\u2212signed) <br \/> purpose => &#8216;sslCA,server&#8217; <br \/> # client certificate <br \/> purpose => &#8216;client&#8217;,<\/p>\n<p style=\"margin-left:17%;\">ext [{ sn => .., data => &#8230; }, &#8230; ]<\/p>\n<p style=\"margin-left:29%;\">List of extensions. The type of the extension can be specified as name with &#8220;sn&#8221; or as <small>NID<\/small> with &#8220;nid&#8221; and the data with &#8220;data&#8221;. These data must be in the same syntax as expected within openssl.cnf, e.g. something like &#8220;OCSP;URI=http:\/\/&#8230;&#8221;. Additionally the critical flag can be set with &#8220;critical =&#8221; 1>.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"11%\">\n<p>key key<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"71%\">\n<p>use given key as key for certificate, otherwise a new one will be generated and returned<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\">issuer_cert cert<\/p>\n<p style=\"margin-left:29%;\">set issuer for new certificate<\/p>\n<p style=\"margin-left:17%;\">issuer_key key<\/p>\n<p style=\"margin-left:29%;\">sign new certificate with given key<\/p>\n<p style=\"margin-left:17%;\">issuer [ cert, key ]<\/p>\n<p style=\"margin-left:29%;\">Instead of giving issuer_key and issuer_cert as separate arguments they can be given both together.<\/p>\n<p style=\"margin-left:17%;\">digest algorithm<\/p>\n<p style=\"margin-left:29%;\">specify the algorithm used to sign the certificate, default <small>SHA\u2212256.<\/small><\/p>\n<h2>AUTHOR <a name=\"AUTHOR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Steffen Ullrich<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  IO::Socket::SSL::Utils \u2212\u2212 loading, storing, creating certificates and keys <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3699,3007],"class_list":["post-7385","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-iosocketsslutils","tag-man3"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7385","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=7385"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7385\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}