위조를 사용하여 javascript (typescript) 파일의 연결 문자열을 통해 수동 SAS 키 생성을 사용하여 azure-iot-hub에서 401 이상을 테스트하는 데 문제가 있습니다. 자바 스크립트 라이브러리. HostName={resourceUri};SharedAccessKeyName={policyName};SharedAccessKey={key}"
Azure IoT 허브 SAS 주요 매뉴얼 Forge js lib를 통한 HMAC 암호화가 포함 된 연결 문자열을 통한 생성
나 자신 (3,600초 추가) 만료 시간을 계산, 사전에 문자열을 중단하고, 다음과 같은 기능과 함께 SAS 키의 URL PARAMS을 계산하기 위해 계속 다음과 같이 연결 문자열 보이는
입니다 : https://{my-resource-uri}.net/devices/807417987db61b41ZX1F239P3Q?api-version=2016-11-14
내가 01 것을 알 수있다 : 여기
// MSDN recommendation
const encodeUriComponentStrict = (str) => {
return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
return '%' + c.charCodeAt(0).toString(16);
});
}
function hmacHash(password, signingString) {
const hmac = forge.hmac.create();
console.log(`password`, password);
hmac.start('sha256', forge.util.encode64(password));
hmac.update(signingString);
const digested = hmac.digest();
return forge.util.encode64(digested.data);
}
/**
* Creates a Sas key for an azure iot registry
* @param hostName the azure iot resource uri
* @param policy the shared access key name
* @param key the shared access key
* @param expiry int64 representation of expiration time
*/
const createSasKeyForRegistry = (hostName: string, policy: string,
key: string, expiry: number) => {
let sas : any = {
_key: key,
sr: hostName,
se: expiry,
skn: encodeUriComponentStrict(policy),
};
sas.sig = encodeUriComponentStrict(hmacHash(sas._key, stringToSign(sas.sr, sas.se)));
return sas;
}
는 I 콘솔에서 볼 수있는 예시적인 리소스
PUT
의 IoT 디바이스 엔드 포인트헤더는 일반적인 SAS 키 형식으로 추가됩니다 :
"SharedAccessSignature sr={resource-uri}&sig=koNqIJF56tzzBpqWYp4tRvxeWIJEHSLugA2O2weELZ4%3D&se=1492307707&skn=iothubowner"
.
이 모든 것에도 불구하고, 나는 아직도 401을 얻고있다 ... 몇 시간 동안 아무런 성공도없이 노력하고있다. hmac 암호화 기능과 관련이 있는지 궁금한가요? 코드를 확인할 수있는 사람은 누구입니까? 흥미가있는 사람들을 위해 저는 이온 2 어플리케이션 (각도 2를 기반으로 함)과 각도 2의 http 클래스를 사용하여 요청을 수행합니다.
감사합니다.
확실히 그랬습니다. 도와 주셔서 감사합니다! –