MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / DecryptJoinAccept

Function DecryptJoinAccept

pkg/crypto/join_messages.go:50–63  ·  view source on GitHub ↗

DecryptJoinAccept uses AES Encrypt to decrypt a join-accept message - The returned payload contains JoinNonce/AppNonce | NetID | DevAddr | DLSettings | RxDelay | (CFList | CFListType) | MIC - In LoRaWAN 1.0, the AppKey is used - In LoRaWAN 1.1, the NwkKey or JSEncKey is used

(key types.AES128Key, encrypted []byte)

Source from the content-addressed store, hash-verified

48// - In LoRaWAN 1.0, the AppKey is used
49// - In LoRaWAN 1.1, the NwkKey or JSEncKey is used
50func DecryptJoinAccept(key types.AES128Key, encrypted []byte) ([]byte, error) {
51 if len(encrypted) != 16 && len(encrypted) != 32 {
52 return nil, errInvalidJoinAcceptMessageSize.WithAttributes("size", len(encrypted))
53 }
54 cipher, err := aes.NewCipher(key[:])
55 if err != nil {
56 return nil, err
57 }
58 payload := make([]byte, len(encrypted))
59 for i := 0; i < len(encrypted); i += 16 {
60 cipher.Encrypt(payload[i:i+16], encrypted[i:i+16])
61 }
62 return payload, nil
63}
64
65var errInvalidJoinRequestPayloadSize = errInvalidSize("join_request_payload", "join-request payload", "19")
66

Callers 3

decodeJoinAcceptFunction · 0.92
processDownlinkFunction · 0.92
TestJoinAcceptEncryptionFunction · 0.85

Calls 2

EncryptMethod · 0.65
WithAttributesMethod · 0.45

Tested by 1

TestJoinAcceptEncryptionFunction · 0.68