Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* s3cmd: New command [sign]

* S3/Utils.py: New function sign_string()
* S3/S3.py, S3/CloudFront.py: Use sign_string().


git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@378 830e0280-6d2a-0410-9c65-932aecc39d9d
  • Loading branch information...
commit 0b8ea55951f8eecf5b9268b1f9ade841023fae8f 1 parent 9a3c1ab
@mludvig mludvig authored
View
7 ChangeLog
@@ -1,3 +1,10 @@
+2009-02-24 Michal Ludvig <michal@logix.cz>
+
+ * s3cmd: New command [sign]
+ * S3/Utils.py: New function sign_string()
+ * S3/S3.py, S3/CloudFront.py: Use sign_string().
+ * NEWS: Updated.
+
2009-02-17 Michal Ludvig <michal@logix.cz>
* Released version 0.9.9
View
5 NEWS
@@ -1,3 +1,8 @@
+s3cmd 1.0.0
+===========
+* New command 'sign' for signing for instance
+ the POST upload policies.
+
s3cmd 0.9.9 - 2009-02-17
===========
New commands:
View
12 S3/CloudFront.py
@@ -4,26 +4,18 @@
## License: GPL Version 2
import sys
-import base64
import time
import httplib
from logging import debug, info, warning, error
try:
- from hashlib import md5, sha1
-except ImportError:
- from md5 import md5
- import sha as sha1
-import hmac
-
-try:
import xml.etree.ElementTree as ET
except ImportError:
import elementtree.ElementTree as ET
from Config import Config
from Exceptions import *
-from Utils import getTreeFromXml, appendXmlTextNode, getDictFromTree, dateS3toPython
+from Utils import getTreeFromXml, appendXmlTextNode, getDictFromTree, dateS3toPython, sign_string
from S3Uri import S3Uri, S3UriS3
def output(message):
@@ -349,7 +341,7 @@ def create_request(self, operation, dist_id = None, headers = None):
def sign_request(self, headers):
string_to_sign = headers['x-amz-date']
- signature = base64.encodestring(hmac.new(self.config.secret_key, string_to_sign, sha1).digest()).strip()
+ signature = sign_string(string_to_sign)
debug(u"CloudFront.sign_request('%s') = %s" % (string_to_sign, signature))
return signature
View
7 S3/S3.py
@@ -5,7 +5,6 @@
import sys
import os, os.path
-import base64
import time
import httplib
import logging
@@ -14,11 +13,9 @@
from stat import ST_SIZE
try:
- from hashlib import md5, sha1
+ from hashlib import md5
except ImportError:
from md5 import md5
- import sha as sha1
-import hmac
from Utils import *
from SortedDict import SortedDict
@@ -649,7 +646,7 @@ def sign_headers(self, method, resource, headers):
h += "/" + resource['bucket']
h += resource['uri']
debug("SignHeaders: " + repr(h))
- return base64.encodestring(hmac.new(self.config.secret_key, h, sha1).digest()).strip()
+ return sign_string(h)
@staticmethod
def check_bucket_name(bucket, dns_strict = True):
View
10 S3/Utils.py
@@ -10,9 +10,12 @@
import random
import rfc822
try:
- from hashlib import md5
+ from hashlib import md5, sha1
except ImportError:
from md5 import md5
+ import sha as sha1
+import hmac
+import base64
import errno
from logging import debug, info, warning, error
@@ -253,3 +256,8 @@ def unicodise_safe(string, encoding = None):
return unicodise(deunicodise(string, encoding), encoding).replace(u'\ufffd', '?')
+def sign_string(string_to_sign):
+ #debug("string_to_sign: %s" % string_to_sign)
+ signature = base64.encodestring(hmac.new(Config.Config().secret_key, string_to_sign, sha1).digest()).strip()
+ #debug("signature: %s" % signature)
+ return signature
View
8 s3cmd
@@ -1048,6 +1048,12 @@ def cmd_setacl(args):
if retsponse['status'] == 200:
output(u"%s: ACL set to %s %s" % (uri, set_to_acl, seq_label))
+def cmd_sign(args):
+ string_to_sign = args.pop()
+ debug("string-to-sign: %r" % string_to_sign)
+ signature = Utils.sign_string(string_to_sign)
+ output("Signature: %s" % signature)
+
def resolve_list(lst, args):
retval = []
for item in lst:
@@ -1281,6 +1287,8 @@ def get_commands_list():
{"cmd":"cp", "label":"Copy object", "param":"s3://BUCKET1/OBJECT1 s3://BUCKET2[/OBJECT2]", "func":cmd_cp, "argc":2},
{"cmd":"mv", "label":"Move object", "param":"s3://BUCKET1/OBJECT1 s3://BUCKET2[/OBJECT2]", "func":cmd_mv, "argc":2},
{"cmd":"setacl", "label":"Modify Access control list for Bucket or Files", "param":"s3://BUCKET[/OBJECT]", "func":cmd_setacl, "argc":1},
+ {"cmd":"sign", "label":"Sign arbitrary string using the secret key", "param":"STRING-TO-SIGN", "func":cmd_sign, "argc":1},
+
## CloudFront commands
{"cmd":"cflist", "label":"List CloudFront distribution points", "param":"", "func":CfCmd.info, "argc":0},
{"cmd":"cfinfo", "label":"Display CloudFront distribution point parameters", "param":"[cf://DIST_ID]", "func":CfCmd.info, "argc":0},
Please sign in to comment.
Something went wrong with that request. Please try again.