Exemple #1
0
func makePreKeyBundle(tel string, deviceID uint32) (*axolotl.PreKeyBundle, error) {
	pkr, err := getPreKeys(tel, strconv.Itoa(int(deviceID)))
	if err != nil {
		return nil, err
	}

	if len(pkr.Devices) != 1 {
		return nil, fmt.Errorf("no prekeys for contact %s, device %d\n", tel, deviceID)
	}

	d := pkr.Devices[0]

	if d.PreKey == nil {
		return nil, fmt.Errorf("no prekey for contact %s, device %d\n", tel, deviceID)
	}

	decPK, err := decodeKey(d.PreKey.PublicKey)
	if err != nil {
		return nil, err
	}

	if d.SignedPreKey == nil {
		return nil, fmt.Errorf("no signed prekey for contact %s, device %d\n", tel, deviceID)
	}

	decSPK, err := decodeKey(d.SignedPreKey.PublicKey)
	if err != nil {
		return nil, err
	}

	decSig, err := decodeSignature(d.SignedPreKey.Signature)
	if err != nil {
		return nil, err
	}

	decIK, err := decodeKey(pkr.IdentityKey)
	if err != nil {
		return nil, err
	}

	pkb, err := axolotl.NewPreKeyBundle(
		d.RegistrationID, d.DeviceID, d.PreKey.ID,
		axolotl.NewECPublicKey(decPK), int32(d.SignedPreKey.ID), axolotl.NewECPublicKey(decSPK),
		decSig, axolotl.NewIdentityKey(decIK))
	if err != nil {
		return nil, err
	}

	return pkb, nil
}
Exemple #2
0
func makePreKeyBundle(tel string) (*axolotl.PreKeyBundle, error) {
	pkr, err := getPreKeys(tel)
	if err != nil {
		return nil, err
	}

	ndev := len(pkr.Devices)

	pkbs := make([]*axolotl.PreKeyBundle, ndev)

	for i, d := range pkr.Devices {
		if d.PreKey == nil {
			return nil, fmt.Errorf("No prekey for contact %s, device %d\n", tel, i)
		}

		decPK, err := decodeKey(d.PreKey.PublicKey)
		if err != nil {
			return nil, err
		}

		decSPK, err := decodeKey(d.SignedPreKey.PublicKey)
		if err != nil {
			return nil, err
		}

		decSig, err := decodeSignature(d.SignedPreKey.Signature)
		if err != nil {
			return nil, err
		}

		decIK, err := decodeKey(pkr.IdentityKey)
		if err != nil {
			return nil, err
		}

		pkbs[i], err = axolotl.NewPreKeyBundle(
			d.RegistrationID, d.DeviceID, d.PreKey.ID,
			axolotl.NewECPublicKey(decPK), int32(d.SignedPreKey.ID), axolotl.NewECPublicKey(decSPK),
			decSig, axolotl.NewIdentityKey(decIK))
		if err != nil {
			return nil, err
		}
	}

	return pkbs[0], nil
}