Beispiel #1
0
/* Verifies that a PolicyApproveMessage has been properly constructed.
 *
 * Arguments:
 *	su         = the suite that the insurer's public key was derived from.
 *      insuredKey = the public key of the insured or the client
 *      insurerKey = the public key of the insurer or "trustee"
 *
 * Returns:
 *	whether or not the message is valid.
 */
func (msg *PolicyApprovedMessage) verifyCertificate(su abstract.Suite,
	insuredKey abstract.Point) bool {

	set := anon.Set{msg.PubKey}
	_, err := anon.Verify(su, msg.Message, set, nil, msg.Signature)
	correctMsg := msg.PubKey.String() + " insures " + insuredKey.String()
	return err == nil && correctMsg == string(msg.Message)
}
Beispiel #2
0
// NewServerIdentity creates a new ServerIdentity based on a public key and with a slice
// of IP-addresses where to find that entity. The Id is based on a
// version5-UUID which can include a URL that is based on it's public key.
func NewServerIdentity(public abstract.Point, addresses ...string) *ServerIdentity {
	url := NamespaceURL + "id/" + public.String()
	return &ServerIdentity{
		Public:    public,
		Addresses: addresses,
		ID:        ServerIdentityID(uuid.NewV5(uuid.NamespaceURL, url)),
	}
}
Beispiel #3
0
/* Adds a new connection to the connection manager
 *
 * Arguments:
 * 	theirkey = the key of the peer that this server wishes to connect to
 *
 * Returns:
 * 	An error denoting whether creating the new connection was successful.
 */
func (gcm *ChanConnManager) AddConn(theirKey abstract.Point) error {
	newConn, err := coconet.NewGoConn(gcm.dir, gcm.pubKey.String(),
		theirKey.String())
	if err != nil {
		return err
	}
	gcm.peerMap[theirKey.String()] = newConn
	return nil
}
func (c *Coordinator) AddClient(key abstract.Point, val *net.UDPAddr) {
	// delete the client who has same ip address
	for k, v := range c.Clients {
		if v.String() == val.String() {
			delete(c.Clients, k)
			break
		}
	}
	c.Clients[key.String()] = val
}
Beispiel #5
0
/* Creates a new policy-approved message
 *
 * Arguments:
 *	kp       = the private/public key of the insuring server.
 *      theirKey = the public key of the server who requested the insurance
 *
 * Returns:
 *	A new policy approved message.
 *
 * NOTE:
 *	The approved certificate is a string of the form:
 *     		"My_Public_Key insures Their_Public_Key"
 *
 *	It will always be of this form for easy validation.
 */
func (msg *PolicyApprovedMessage) createMessage(kp *config.KeyPair,
	theirKey abstract.Point) *PolicyApprovedMessage {

	set := anon.Set{kp.Public}
	approveMsg := kp.Public.String() + " insures " + theirKey.String()
	msg.PubKey = kp.Public
	msg.Message = []byte(approveMsg)
	msg.Signature = anon.Sign(kp.Suite, random.Stream, msg.Message,
		set, nil, 0, kp.Secret)
	return msg
}
Beispiel #6
0
/* Get a message from a given peer.
 *
 * Arguments:
 *	 p = the public key of the origin
 *	 bum = a buffer for receiving the message
 *
 * Returns:
 *	An error denoting whether the get to the buffer was successfull
 */
func (gcm ChanConnManager) Get(p abstract.Point, bum coconet.BinaryUnmarshaler) error {
	return gcm.peerMap[p.String()].Get(bum)
}
Beispiel #7
0
/* Put a message to a given peer.
 *
 * Arguments:
 * 	p = the public key of the destination
 * 	data = the message to send
 *
 * Returns:
 * 	An error denoting whether the put was successfull
 */
func (gcm *ChanConnManager) Put(p abstract.Point, data coconet.BinaryMarshaler) error {
	return gcm.peerMap[p.String()].Put(data)
}
func (c *Coordinator) AddIntoRepMap(key abstract.Point, val []byte) {
	keyStr := key.String()
	c.ReputationKeyMap[keyStr] = key
	c.ReputationMap[keyStr] = val
}
func (c *Coordinator) AddIntoDecryptedMap(key abstract.Point, val int) {
	keyStr := key.String()
	c.DecryptedKeysMap[keyStr] = key
	c.DecryptedReputationMap[keyStr] = val
}
Beispiel #10
0
// get reputation
func (c *Coordinator) GetReputation(key abstract.Point) int {
	return c.DecryptedReputationMap[key.String()]
}