Ejemplo n.º 1
0
// Format gives you the partial key in the canonical representation including
// ----BEGIN/END headers.
func (k *PartialKey) String() string {
	b := new(buffer.Buffer)
	k.WriteBuffer(b)
	if b.Error != nil {
		panic(errors.New("invalid partial key: " + b.Error.Error()))
	}

	return HEADER + "\n" + lineWrap(b.String(), 64) + FOOTER + "\n"
}
Ejemplo n.º 2
0
// String produces the line-wrapped base-64 version of the challenge,
// suitable for being passed to NewSignRequest()
func (request *SignRequest) String() string {
	b := new(buffer.Buffer)

	request.WriteBuffer(b)

	if b.Error != nil {
		panic(errors.New("invalid sign request: " + b.Error.Error()))
	}

	return SIGN_REQUEST_HEADER + "\n" + lineWrap(b.String(), 64) + SIGN_REQUEST_FOOTER + "\n"
}
Ejemplo n.º 3
0
// String returns the public key in the same format as used by ssh
func (p *PublicKey) String() string {
	b := new(buffer.Buffer)

	p.WriteBuffer(b)

	if b.Error != nil {
		panic(errors.New("invalid public key: " + b.Error.Error()))
	}

	return PUBLIC_KEY_TYPE + " " + b.String() + "\n"
}
Ejemplo n.º 4
0
// ReadBuffer reads the public key from a buffer.
func (p *PublicKey) ReadBuffer(b *buffer.Buffer) error {

	t := b.ScanString()
	e := b.ScanMPInt()
	n := b.ScanMPInt()

	if t != PUBLIC_KEY_TYPE {
		return ErrPublicKeyFormat
	}

	if e.Cmp(big.NewInt(EXPONENT)) != 0 {
		return ErrPublicKeyFormat
	}

	p.E = EXPONENT
	p.N = n

	return nil
}
Ejemplo n.º 5
0
// ReadBuffer reads a SignRequest from a buffer.
func (request *SignRequest) ReadBuffer(b *buffer.Buffer) error {

	publicKey := new(PublicKey)
	err := publicKey.ReadBuffer(b)
	if err != nil {
		return err
	}

	msg := b.ScanMPInt()

	if msg.Cmp(publicKey.N) >= 0 {
		return errors.New("cannot sign message > N")
	}

	request.Key = publicKey
	request.M = msg

	return nil
}
Ejemplo n.º 6
0
// WriteBuffer writes the PartialKey to a buffer
func (k *PartialKey) WriteBuffer(b *buffer.Buffer) {
	b.AddString(KEY_TYPE)
	b.AddMPInt(big.NewInt(int64(k.E)))
	b.AddMPInt(k.N)
	b.AddMPInt(k.D)
}
Ejemplo n.º 7
0
// WriteBuffer writes the public key to a buffer.
func (p *PublicKey) WriteBuffer(b *buffer.Buffer) {
	b.AddString(PUBLIC_KEY_TYPE)
	b.AddMPInt(big.NewInt(int64(p.E)))
	b.AddMPInt(p.N)
}
Ejemplo n.º 8
0
func (request *SignRequest) WriteBuffer(b *buffer.Buffer) {
	request.Key.WriteBuffer(b)
	b.AddMPInt(request.M)
}
Ejemplo n.º 9
0
func (a *AuthRequest) unsignedBuffer() *buffer.Buffer {
	b := buffer.Buffer{}
	b.AddBuffer(a.ChallengeBuffer)
	b.AddString(a.RequestUrl)
	b.AddString(a.Username)
	b.AddString(a.ServiceName)
	b.AddString(a.AuthMethod)
	b.AddString(a.SigningAlgorithm)
	//	b.AddVarBytes(publicKeyBytes(a.PublicKey))
	panic("todo")
	return &b
}