Joe Gregorio | 2401bd6 | 2011-12-15 09:18:49 -0500 | [diff] [blame] | 1 | |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 3 | <html><head><title>Python: module oauth2client.crypt</title> |
| 4 | </head><body bgcolor="#f0f0f8"> |
| 5 | |
| 6 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
| 7 | <tr bgcolor="#7799ee"> |
| 8 | <td valign=bottom> <br> |
| 9 | <font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="oauth2client.html"><font color="#ffffff">oauth2client</font></a>.crypt</strong></big></big></font></td |
| 10 | ><td align=right valign=bottom |
Joe Gregorio | 3d55ac5 | 2012-02-21 10:11:19 -0500 | [diff] [blame^] | 11 | ><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient-release/oauth2client/crypt.py">/usr/local/google/home/jcgregorio/projects/apiclient-release/oauth2client/crypt.py</a></font></td></tr></table> |
Joe Gregorio | 2401bd6 | 2011-12-15 09:18:49 -0500 | [diff] [blame] | 12 | <p><tt># -*- coding: utf-8 -*-<br> |
| 13 | #<br> |
| 14 | # Copyright (C) 2011 Google Inc.<br> |
| 15 | #<br> |
| 16 | # Licensed under the Apache License, Version 2.0 (the "License");<br> |
| 17 | # you may not use this file except in compliance with the License.<br> |
| 18 | # You may obtain a copy of the License at<br> |
| 19 | #<br> |
| 20 | # <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a><br> |
| 21 | #<br> |
| 22 | # Unless required by applicable law or agreed to in writing, software<br> |
| 23 | # distributed under the License is distributed on an "AS IS" BASIS,<br> |
| 24 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br> |
| 25 | # See the License for the specific language governing permissions and<br> |
| 26 | # limitations under the License.</tt></p> |
| 27 | <p> |
| 28 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 29 | <tr bgcolor="#aa55cc"> |
| 30 | <td colspan=3 valign=bottom> <br> |
| 31 | <font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> |
| 32 | |
| 33 | <tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> |
| 34 | <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="base64.html">base64</a><br> |
| 35 | <a href="OpenSSL.crypto.html">OpenSSL.crypto</a><br> |
| 36 | </td><td width="25%" valign=top><a href="hashlib.html">hashlib</a><br> |
| 37 | <a href="logging.html">logging</a><br> |
Joe Gregorio | 3d55ac5 | 2012-02-21 10:11:19 -0500 | [diff] [blame^] | 38 | </td><td width="25%" valign=top><a href="json.html">json</a><br> |
Joe Gregorio | 2401bd6 | 2011-12-15 09:18:49 -0500 | [diff] [blame] | 39 | <a href="time.html">time</a><br> |
| 40 | </td><td width="25%" valign=top></td></tr></table></td></tr></table><p> |
| 41 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 42 | <tr bgcolor="#ee77aa"> |
| 43 | <td colspan=3 valign=bottom> <br> |
| 44 | <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> |
| 45 | |
| 46 | <tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> |
| 47 | <td width="100%"><dl> |
| 48 | <dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a> |
| 49 | </font></dt><dd> |
| 50 | <dl> |
| 51 | <dt><font face="helvetica, arial"><a href="oauth2client.crypt.html#Signer">Signer</a> |
| 52 | </font></dt><dt><font face="helvetica, arial"><a href="oauth2client.crypt.html#Verifier">Verifier</a> |
| 53 | </font></dt></dl> |
| 54 | </dd> |
| 55 | <dt><font face="helvetica, arial"><a href="exceptions.html#Exception">exceptions.Exception</a>(<a href="exceptions.html#BaseException">exceptions.BaseException</a>) |
| 56 | </font></dt><dd> |
| 57 | <dl> |
| 58 | <dt><font face="helvetica, arial"><a href="oauth2client.crypt.html#AppIdentityError">AppIdentityError</a> |
| 59 | </font></dt></dl> |
| 60 | </dd> |
| 61 | </dl> |
| 62 | <p> |
| 63 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 64 | <tr bgcolor="#ffc8d8"> |
| 65 | <td colspan=3 valign=bottom> <br> |
| 66 | <font color="#000000" face="helvetica, arial"><a name="AppIdentityError">class <strong>AppIdentityError</strong></a>(<a href="exceptions.html#Exception">exceptions.Exception</a>)</font></td></tr> |
| 67 | |
| 68 | <tr><td bgcolor="#ffc8d8"><tt> </tt></td><td> </td> |
| 69 | <td width="100%"><dl><dt>Method resolution order:</dt> |
| 70 | <dd><a href="oauth2client.crypt.html#AppIdentityError">AppIdentityError</a></dd> |
| 71 | <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd> |
| 72 | <dd><a href="exceptions.html#BaseException">exceptions.BaseException</a></dd> |
| 73 | <dd><a href="__builtin__.html#object">__builtin__.object</a></dd> |
| 74 | </dl> |
| 75 | <hr> |
| 76 | Data descriptors defined here:<br> |
| 77 | <dl><dt><strong>__weakref__</strong></dt> |
| 78 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 79 | </dl> |
| 80 | <hr> |
| 81 | Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br> |
| 82 | <dl><dt><a name="AppIdentityError-__init__"><strong>__init__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__init__">__init__</a>(...) initializes x; see x.__class__.__doc__ for signature</tt></dd></dl> |
| 83 | |
| 84 | <hr> |
| 85 | Data and other attributes inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br> |
| 86 | <dl><dt><strong>__new__</strong> = <built-in method __new__ of type object><dd><tt>T.<a href="#AppIdentityError-__new__">__new__</a>(S, ...) -> a new <a href="__builtin__.html#object">object</a> with type S, a subtype of T</tt></dl> |
| 87 | |
| 88 | <hr> |
| 89 | Methods inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br> |
| 90 | <dl><dt><a name="AppIdentityError-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__delattr__">__delattr__</a>('name') <==> del x.name</tt></dd></dl> |
| 91 | |
| 92 | <dl><dt><a name="AppIdentityError-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__getattribute__">__getattribute__</a>('name') <==> x.name</tt></dd></dl> |
| 93 | |
| 94 | <dl><dt><a name="AppIdentityError-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__getitem__">__getitem__</a>(y) <==> x[y]</tt></dd></dl> |
| 95 | |
| 96 | <dl><dt><a name="AppIdentityError-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__getslice__">__getslice__</a>(i, j) <==> x[i:j]<br> |
| 97 | <br> |
| 98 | Use of negative indices is not supported.</tt></dd></dl> |
| 99 | |
| 100 | <dl><dt><a name="AppIdentityError-__reduce__"><strong>__reduce__</strong></a>(...)</dt></dl> |
| 101 | |
| 102 | <dl><dt><a name="AppIdentityError-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__repr__">__repr__</a>() <==> repr(x)</tt></dd></dl> |
| 103 | |
| 104 | <dl><dt><a name="AppIdentityError-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__setattr__">__setattr__</a>('name', value) <==> x.name = value</tt></dd></dl> |
| 105 | |
| 106 | <dl><dt><a name="AppIdentityError-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl> |
| 107 | |
| 108 | <dl><dt><a name="AppIdentityError-__str__"><strong>__str__</strong></a>(...)</dt><dd><tt>x.<a href="#AppIdentityError-__str__">__str__</a>() <==> str(x)</tt></dd></dl> |
| 109 | |
| 110 | <dl><dt><a name="AppIdentityError-__unicode__"><strong>__unicode__</strong></a>(...)</dt></dl> |
| 111 | |
| 112 | <hr> |
| 113 | Data descriptors inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br> |
| 114 | <dl><dt><strong>__dict__</strong></dt> |
| 115 | </dl> |
| 116 | <dl><dt><strong>args</strong></dt> |
| 117 | </dl> |
| 118 | <dl><dt><strong>message</strong></dt> |
| 119 | </dl> |
| 120 | </td></tr></table> <p> |
| 121 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 122 | <tr bgcolor="#ffc8d8"> |
| 123 | <td colspan=3 valign=bottom> <br> |
| 124 | <font color="#000000" face="helvetica, arial"><a name="Signer">class <strong>Signer</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr> |
| 125 | |
| 126 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 127 | <td colspan=2><tt>Signs messages with a private key.<br> </tt></td></tr> |
| 128 | <tr><td> </td> |
| 129 | <td width="100%">Methods defined here:<br> |
| 130 | <dl><dt><a name="Signer-__init__"><strong>__init__</strong></a>(self, pkey)</dt><dd><tt>Constructor.<br> |
| 131 | <br> |
| 132 | Args:<br> |
| 133 | pkey, OpenSSL.crypto.PKey, The private key to sign with.</tt></dd></dl> |
| 134 | |
| 135 | <dl><dt><a name="Signer-sign"><strong>sign</strong></a>(self, message)</dt><dd><tt>Signs a message.<br> |
| 136 | <br> |
| 137 | Args:<br> |
| 138 | message: string, Message to be signed.<br> |
| 139 | <br> |
| 140 | Returns:<br> |
| 141 | string, The signature of the message for the given key.</tt></dd></dl> |
| 142 | |
| 143 | <hr> |
| 144 | Static methods defined here:<br> |
| 145 | <dl><dt><a name="Signer-from_string"><strong>from_string</strong></a>(key, password<font color="#909090">='notasecret'</font>)</dt><dd><tt>Construct a <a href="#Signer">Signer</a> instance from a string.<br> |
| 146 | <br> |
| 147 | Args:<br> |
| 148 | key: string, private key in P12 format.<br> |
| 149 | password: string, password for the private key file.<br> |
| 150 | <br> |
| 151 | Returns:<br> |
| 152 | <a href="#Signer">Signer</a> instance.<br> |
| 153 | <br> |
| 154 | Raises:<br> |
| 155 | OpenSSL.crypto.Error if the key can't be parsed.</tt></dd></dl> |
| 156 | |
| 157 | <hr> |
| 158 | Data descriptors defined here:<br> |
| 159 | <dl><dt><strong>__dict__</strong></dt> |
| 160 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 161 | </dl> |
| 162 | <dl><dt><strong>__weakref__</strong></dt> |
| 163 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 164 | </dl> |
| 165 | </td></tr></table> <p> |
| 166 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 167 | <tr bgcolor="#ffc8d8"> |
| 168 | <td colspan=3 valign=bottom> <br> |
| 169 | <font color="#000000" face="helvetica, arial"><a name="Verifier">class <strong>Verifier</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr> |
| 170 | |
| 171 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 172 | <td colspan=2><tt>Verifies the signature on a message.<br> </tt></td></tr> |
| 173 | <tr><td> </td> |
| 174 | <td width="100%">Methods defined here:<br> |
| 175 | <dl><dt><a name="Verifier-__init__"><strong>__init__</strong></a>(self, pubkey)</dt><dd><tt>Constructor.<br> |
| 176 | <br> |
| 177 | Args:<br> |
| 178 | pubkey, OpenSSL.crypto.PKey, The public key to verify with.</tt></dd></dl> |
| 179 | |
| 180 | <dl><dt><a name="Verifier-verify"><strong>verify</strong></a>(self, message, signature)</dt><dd><tt>Verifies a message against a signature.<br> |
| 181 | <br> |
| 182 | Args:<br> |
| 183 | message: string, The message to verify.<br> |
| 184 | signature: string, The signature on the message.<br> |
| 185 | <br> |
| 186 | Returns:<br> |
| 187 | True if message was singed by the private key associated with the public<br> |
| 188 | key that this <a href="__builtin__.html#object">object</a> was constructed with.</tt></dd></dl> |
| 189 | |
| 190 | <hr> |
| 191 | Static methods defined here:<br> |
| 192 | <dl><dt><a name="Verifier-from_string"><strong>from_string</strong></a>(key_pem, is_x509_cert)</dt><dd><tt>Construct a Verified instance from a string.<br> |
| 193 | <br> |
| 194 | Args:<br> |
| 195 | key_pem: string, public key in PEM format.<br> |
| 196 | is_x509_cert: bool, True if key_pem is an X509 cert, otherwise it is<br> |
| 197 | expected to be an RSA key in PEM format.<br> |
| 198 | <br> |
| 199 | Returns:<br> |
| 200 | <a href="#Verifier">Verifier</a> instance.<br> |
| 201 | <br> |
| 202 | Raises:<br> |
| 203 | OpenSSL.crypto.Error if the key_pem can't be parsed.</tt></dd></dl> |
| 204 | |
| 205 | <hr> |
| 206 | Data descriptors defined here:<br> |
| 207 | <dl><dt><strong>__dict__</strong></dt> |
| 208 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 209 | </dl> |
| 210 | <dl><dt><strong>__weakref__</strong></dt> |
| 211 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 212 | </dl> |
| 213 | </td></tr></table></td></tr></table><p> |
| 214 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 215 | <tr bgcolor="#eeaa77"> |
| 216 | <td colspan=3 valign=bottom> <br> |
| 217 | <font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> |
| 218 | |
| 219 | <tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td> |
| 220 | <td width="100%"><dl><dt><a name="-make_signed_jwt"><strong>make_signed_jwt</strong></a>(signer, payload)</dt><dd><tt>Make a signed JWT.<br> |
| 221 | <br> |
| 222 | See <a href="http://self-issued.info/docs/draft-jones-json-web-token.html">http://self-issued.info/docs/draft-jones-json-web-token.html</a>.<br> |
| 223 | <br> |
| 224 | Args:<br> |
| 225 | signer: crypt.<a href="#Signer">Signer</a>, Cryptographic signer.<br> |
| 226 | payload: dict, Dictionary of data to convert to JSON and then sign.<br> |
| 227 | <br> |
| 228 | Returns:<br> |
| 229 | string, The JWT for the payload.</tt></dd></dl> |
| 230 | <dl><dt><a name="-verify_signed_jwt_with_certs"><strong>verify_signed_jwt_with_certs</strong></a>(jwt, certs, audience)</dt><dd><tt>Verify a JWT against public certs.<br> |
| 231 | <br> |
| 232 | See <a href="http://self-issued.info/docs/draft-jones-json-web-token.html">http://self-issued.info/docs/draft-jones-json-web-token.html</a>.<br> |
| 233 | <br> |
| 234 | Args:<br> |
| 235 | jwt: string, A JWT.<br> |
| 236 | certs: dict, Dictionary where values of public keys in PEM format.<br> |
| 237 | audience: string, The audience, 'aud', that this JWT should contain. If<br> |
| 238 | None then the JWT's 'aud' parameter is not verified.<br> |
| 239 | <br> |
| 240 | Returns:<br> |
| 241 | dict, The deserialized JSON payload in the JWT.<br> |
| 242 | <br> |
| 243 | Raises:<br> |
| 244 | <a href="#AppIdentityError">AppIdentityError</a> if any checks are failed.</tt></dd></dl> |
| 245 | </td></tr></table><p> |
| 246 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 247 | <tr bgcolor="#55aa55"> |
| 248 | <td colspan=3 valign=bottom> <br> |
| 249 | <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> |
| 250 | |
| 251 | <tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> |
| 252 | <td width="100%"><strong>AUTH_TOKEN_LIFETIME_SECS</strong> = 300<br> |
| 253 | <strong>CLOCK_SKEW_SECS</strong> = 300<br> |
| 254 | <strong>MAX_TOKEN_LIFETIME_SECS</strong> = 86400</td></tr></table> |
| 255 | </body></html> |