2012-03-23 3 views
1

나는 파이썬에서 초보자입니다. 비밀번호 + 사람 + 부트 스트랩 + 부트 스트랩 : 나는스 리프트 개체를 SHA1 다이제스트로 변환

struct AuthSalt { 
    1: required i64 client, /* random data */ 
    2: required i64 server, /* data from previous answer */ 
} 

struct AuthRequest { 
    1: required AuthSalt bootstrap, 
    2: required string who,   /* login */ 
    3: required string signature,  /* SHA-1: bootstrap + password + who + bootstrap. */ 
} 

exception NotAuthorisedException { 
    1: required string description 
} 

service Bookworm { 
    AuthResponse Authenticate(1: required AuthRequest a, 2: required string locale) 
     throws (1: NotAuthorisedException e) 
} 

내가이 알고리즘으로를 사용하여 SHA1 다이제스트를 생성해야 드리프트 프로토콜을 사용하여 서버에서 작동하려고합니다.

dig = hashlib.sha1 
bootstrap = AuthSalt(0, 0) 
dig.update(bootstrap) 
dig.update(password + who) 
dig.update(bootstrap) 

그러나 갱신 방법의 인수 유형에만 문자열과 내가 문자열로 부트 스트랩을 변환하는 방법을 이해할 수 없다 :

내가 이것을 사용 부트 스트랩을 만듭니다.

SHA_CTX c; 
      ::SHA1_Init(&c); 
      ::SHA1_Update(&c, &bootstrap, sizeof(bootstrap)); 
      ::SHA1_Update(&c, password.c_str(), password.size()); 
      ::SHA1_Update(&c, who.c_str(), who.size()); 
      ::SHA1_Update(&c, &bootstrap, sizeof(bootstrap)); 
      ::SHA1_Final(digest, &c); 

누군가가 파이썬을 사용하여 작업을 수행하는 방법을 설명 할 수 :

는 C++에서이 코드는 같다?

미리 감사드립니다.

답변

1

bootstrap 대신 str(bootstrap)이 작동한다고 가정합니다.

+0

없음으로,이 올바르지 않습니다. C++ 코드를 자세히 살펴보십시오. str (bootstrap)을 이해하기 때문에 이것은 객체의 문자열 표현이지만 부트 스트랩에서 2 바이트의 문자열 표현이 필요합니다. 부트 스트랩은 구조체입니다 (64 비트 부호있는 정수). str (bootstrap.client) + str (bootstrap.server) - 또한 올바르지 않습니다. – Ilya

0

이 내가해야 할 무엇이다 : 8 바이트로

for x in tuple(struct.pack("Q",bootstrap.client)): 
    dig.update(x) 

변환 I64 및 업데이트 해시를 모든 바이트

관련 문제