⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proxy_certificates.txt

📁 开源的ssl算法openssl,版本0.9.8H
💻 TXT
字号:
<DRAFT!>			HOWTO proxy certificates0. WARNINGNONE OF THE CODE PRESENTED HERE HAVE BEEN CHECKED!  They are just anexample to show you how things can be done.  There may be typos ortype conflicts, and you will have to resolve them.1. IntroductionProxy certificates are defined in RFC 3820.  They are really usualcertificates with the mandatory extension proxyCertInfo.Proxy certificates are issued by an End Entity (typically a user),either directly with the EE certificate as issuing certificate, or byextension through an already issued proxy certificate..  They are usedto extend rights to some other entity (a computer process, typically,or sometimes to the user itself), so it can perform operations in thename of the owner of the EE certificate.See http://www.ietf.org/rfc/rfc3820.txt for more information.2. A warning about proxy certificatesNoone seems to have tested proxy certificates with security in mind.Basically, to this date, it seems that proxy certificates have onlybeen used in a world that's highly aware of them.  What would happenif an unsuspecting application is to validate a chain of certificatesthat contains proxy certificates?  It would usually consider the leafto be the certificate to check for authorisation data, and since proxycertificates are controlled by the EE certificate owner alone, it'swould be normal to consider what the EE certificate owner could dowith them.subjectAltName and issuerAltName are forbidden in proxy certificates,and this is enforced in OpenSSL.  The subject must be the same as theissuer, with one commonName added on.Possible threats are, as far as has been imagined so far: - impersonation through commonName (think server certificates). - use of additional extensions, possibly non-standard ones used in   certain environments, that would grant extra or different   authorisation rights.For this reason, OpenSSL requires that the use of proxy certificatesbe explicitely allowed.  Currently, this can be done using thefollowing methods: - if the application calls X509_verify_cert() itself, it can do the   following prior to that call (ctx is the pointer passed in the call   to X509_verify_cert()):	X509_STORE_CTX_set_flags(ctx, X509_V_FLAG_ALLOW_PROXY_CERTS); - in all other cases, proxy certificate validation can be enabled   before starting the application by setting the envirnoment variable   OPENSSL_ALLOW_PROXY with some non-empty value.There are thoughts to allow proxy certificates with a line in thedefault openssl.cnf, but that's still in the future.3. How to create proxy cerificatesIt's quite easy to create proxy certificates, by taking advantage ofthe lack of checks of the 'openssl x509' application (*ahem*).  Butfirst, you need to create a configuration section that contains adefinition of the proxyCertInfo extension, a little like this:  [ v3_proxy ]  # A proxy certificate MUST NEVER be a CA certificate.  basicConstraints=CA:FALSE  # Usual authority key ID  authorityKeyIdentifier=keyid,issuer:always  # Now, for the extension that marks this certificate as a proxy one  proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:1,policy:text:ABIt's also possible to give the proxy extension in a separate section:  proxyCertInfo=critical,@proxy_ext  [ proxy_ext ]  language=id-ppl-anyLanguage  pathlen=0  policy=text:BCThe policy value has a specific syntax, {syntag}:{string}, where thesyntag determines what will be done with the string.  The recognisedsyntags are as follows:  text	indicates that the string is simply the bytes, not	encoded in any kind of way:		policy=text:r鋕sm鰎g錽	Previous versions of this design had a specific tag	for UTF-8 text.  However, since the bytes are copied	as-is anyway, there's no need for it.  Instead, use	the text: tag, like this:		policy=text:r盲ksm枚rg氓s  hex	indicates the string is encoded in hex, with colons	between each byte (every second hex digit):		policy=hex:72:E4:6B:73:6D:F6:72:67:E5:73	Previous versions of this design had a tag to insert a	complete DER blob.  However, the only legal use for	this would be to surround the bytes that would go with	the hex: tag with what's needed to construct a correct	OCTET STRING.  Since hex: does that, the DER tag felt	superfluous, and was therefore removed.  file	indicates that the text of the policy should really be	taken from a file.  The string is then really a file	name.  This is useful for policies that are large	(more than a few of lines) XML documents, for example.The 'policy' setting can be split up in multiple lines like this:  0.policy=This is  1.polisy= a multi-  2.policy=line policy.NOTE: the proxy policy value is the part that determines the rightsgranted to the process using the proxy certificate.  The value iscompletely dependent on the application reading and interpretting it!Now that you have created an extension section for your proxycertificate, you can now easily create a proxy certificate like this:  openssl req -new -config openssl.cnf \	  -out proxy.req -keyout proxy.key  openssl x509 -req -CAcreateserial -in proxy.req -days 7 \	  -out proxy.crt -CA user.crt -CAkey user.key \	  -extfile openssl.cnf -extensions v3_proxyIt's just as easy to create a proxy certificate using another proxycertificate as issuer (note that I'm using a different configurationsection for it):  openssl req -new -config openssl.cnf \	  -out proxy2.req -keyout proxy2.key  openssl x509 -req -CAcreateserial -in proxy2.req -days 7 \	  -out proxy2.crt -CA proxy.crt -CAkey proxy.key \	  -extfile openssl.cnf -extensions v3_proxy24. How to have your application interpret the policy?The basic way to interpret proxy policies is to prepare some defaultrights, then do a check of the proxy certificate against the a chainof proxy certificates, user certificate and CA certificates, and seewhat rights came out by the end.  Sounds easy, huh?  It almost is.The slightly complicated part is how to pass data between yourapplication and the certificate validation procedure.You need the following ingredients: - a callback routing that will be called for every certificate that's   validated.  It will be called several times for each certificates,   so you must be attentive to when it's a good time to do the proxy   policy interpretation and check, as well as to fill in the defaults   when the EE certificate is checked. - a structure of data that's shared between your application code and   the callback. - a wrapper function that sets it all up. - an ex_data index function that creates an index into the generic   ex_data store that's attached to an X509 validation context.This is some cookbook code for you to fill in:  /* In this example, I will use a view of granted rights as a bit     array, one bit for each possible right.  */  typedef struct your_rights {    unsigned char rights[total_rights / 8];  } YOUR_RIGHTS;  /* The following procedure will create an index for the ex_data     store in the X509 validation context the first time it's called.     Subsequent calls will return the same index.  */  static int get_proxy_auth_ex_data_idx(void)  {    static volatile int idx = -1;    if (idx < 0)      {        CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);        if (idx < 0)          {            idx = X509_STORE_CTX_get_ex_new_index(0,                                                  "for verify callback",                                                  NULL,NULL,NULL);          }        CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);      }    return idx;  }  /* Callback to be given to the X509 validation procedure.  */  static int verify_callback(int ok, X509_STORE_CTX *ctx)  {    if (ok == 1) /* It's REALLY important you keep the proxy policy                    check within this secion.  It's important to know                    that when ok is 1, the certificates are checked                    from top to bottom.  You get the CA root first,                    followed by the possible chain of intermediate                    CAs, followed by the EE certificate, followed by                    the possible proxy certificates.  */      {        X509 *xs = ctx->current_cert;        if (xs->ex_flags & EXFLAG_PROXY)          {	    YOUR_RIGHTS *rights =              (YOUR_RIGHTS *)X509_STORE_CTX_get_ex_data(ctx,                get_proxy_auth_ex_data_idx());            PROXY_CERT_INFO_EXTENSION *pci =              X509_get_ext_d2i(xs, NID_proxyCertInfo, NULL, NULL);            switch (OBJ_obj2nid(pci->proxyPolicy->policyLanguage))              {              case NID_Independent:                /* Do whatever you need to grant explicit rights to                   this particular proxy certificate, usually by                   pulling them from some database.  If there are none                   to be found, clear all rights (making this and any                   subsequent proxy certificate void of any rights).                */                memset(rights->rights, 0, sizeof(rights->rights));                break;              case NID_id_ppl_inheritAll:                /* This is basically a NOP, we simply let the current                   rights stand as they are. */                break;              default:                /* This is usually the most complex section of code.                   You really do whatever you want as long as you                   follow RFC 3820.  In the example we use here, the                   simplest thing to do is to build another, temporary                   bit array and fill it with the rights granted by                   the current proxy certificate, then use it as a                   mask on the accumulated rights bit array, and                   voil

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -