0

ドキュメントの引用:

事前登録が完了すると、アクティベーション コードを Xively API に送信することでデバイスをアクティベートできます。これは、デバイスが初めて起動したことを Xively に通知し、使用できるフィード ID と API キーのプロビジョニングを要求しています。デバイスのアクティベーション コードは、デバイスのシリアル番号とその親製品のプロダクト シークレットを組み合わせた HMAC-SHA1 ハッシュを使用して生成され、誰かがアクティベーション コードからプロダクト シークレットを抽出したり、プロビジョニングで不正にデバイスになりすますことを事実上不可能にします。処理する。

ベストプラクティスとは:

  1. 各デバイスメモリにアクティベーションコードを保持する: 工場でのプログラミングに非常に時間がかかる
  2. 経由でデバイスのウェイクアップ時にアクティベーション コードを計算しますHMAC-SHA1(serialnumber, productid)

私の場合、2番目の方が理にかなっていますが、HMACがAPIドキュメントからどのように計算されるかわかりません。それは単なる文字列連結ですか?パディングはどうですか?

4

2 に答える 2

1

Python でこれを行う方法の例があります。を使用してプロダクト シークレットをバイナリに変換することがわかりbinascii .a2b_hex()ます。

Ruby での別の例を次に示します。

require('openssl')

secret = '488f40ff3d0b2c6188e272f8d86416b73b3cb4ef'
serial = '0123456789'

digest = OpenSSL::Digest::Digest.new('sha1')
puts OpenSSL::HMAC.hexdigest(digest, [secret].pack("H*"), serial)

そして、ここにArduino用のものがあります:

// First, download the library from https://github.com/Cathedrow/Cryptosuite
// and make sure it is installed properly, although until it supports Arduino 1.0,
// it's better to use this fork: https://github.com/jkiv/Cryptosuite
#include "sha1.h"

uint8_t secret[]={
  0x48,0x8f,0x40,0xff,0x3d,0x0b,0x2c,0x61,0x88,0xe2,
  0x72,0xf8,0xd8,0x64,0x16,0xb7,0x3b,0x3c,0xb4,0xef,
};
String serial = "0123456789";
String activation_code;

String convertHash(uint8_t* hash) {
  String returnString;
  int i;
  for (i=0; i<20; i++) {
    returnString += ("0123456789abcdef"[hash[i]>>4]);
    returnString += ("0123456789abcdef"[hash[i]&0xf]);  
  }  
  return returnString;
}

void setup() {
  // Generally you would compute the hash once on start up and store it in flash
  // to avoid doing it each time as it can be a bit slow
  Serial.begin(57600);
  Serial.println("computing hmac sha: ");
  Sha1.initHmac(secret, 20);
  Sha1.print(serial); 
  activation_code = convertHash(Sha1.resultHmac());
  Serial.println(activation_code);
}
于 2013-08-27T09:39:56.830 に答える