aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet/message/msg_revocation.go
blob: 90f8dd180ff0fda772c6251c5a986d81a9b37d6f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// This file is part of gnunet-go, a GNUnet-implementation in Golang.
// Copyright (C) 2019-2022 Bernd Fix  >Y<
//
// gnunet-go is free software: you can redistribute it and/or modify it
// under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// gnunet-go is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: AGPL3.0-or-later

package message

import (
	"fmt"

	"gnunet/crypto"
	"gnunet/util"
)

//----------------------------------------------------------------------
// REVOCATION_QUERY
//----------------------------------------------------------------------

// RevocationQueryMsg is a request message to check if a key is revoked
type RevocationQueryMsg struct {
	MsgSize  uint16          `order:"big"` // total size of message
	MsgType  uint16          `order:"big"` // REVOCATION_QUERY (636)
	Reserved uint32          `order:"big"` // Reserved for future use
	Zone     *crypto.ZoneKey // Zone that is to be checked for revocation
}

// NewRevocationQueryMsg creates a new message for a given zone.
func NewRevocationQueryMsg(zkey *crypto.ZoneKey) *RevocationQueryMsg {
	return &RevocationQueryMsg{
		MsgSize:  40,
		MsgType:  REVOCATION_QUERY,
		Reserved: 0,
		Zone:     zkey,
	}
}

// String returns a human-readable representation of the message.
func (m *RevocationQueryMsg) String() string {
	return fmt.Sprintf("RevocationQueryMsg{zone=%s}", m.Zone.ID())
}

// Header returns the message header in a separate instance.
func (m *RevocationQueryMsg) Header() *Header {
	return &Header{m.MsgSize, m.MsgType}
}

//----------------------------------------------------------------------
// REVOCATION_QUERY_RESPONSE
//----------------------------------------------------------------------

// RevocationQueryResponseMsg is a response message for revocation checks.
type RevocationQueryResponseMsg struct {
	MsgSize uint16 `order:"big"` // total size of message
	MsgType uint16 `order:"big"` // REVOCATION_QUERY_RESPONSE (637)
	Valid   uint32 `order:"big"` // revoked(0), valid(1)
}

// NewRevocationQueryResponseMsg creates a new response for a query.
func NewRevocationQueryResponseMsg(revoked bool) *RevocationQueryResponseMsg {
	valid := 1
	if revoked {
		valid = 0
	}
	return &RevocationQueryResponseMsg{
		MsgSize: 8,
		MsgType: REVOCATION_QUERY_RESPONSE,
		Valid:   uint32(valid),
	}
}

// String returns a human-readable representation of the message.
func (m *RevocationQueryResponseMsg) String() string {
	return fmt.Sprintf("RevocationQueryResponseMsg{valid=%d}", m.Valid)
}

// Header returns the message header in a separate instance.
func (m *RevocationQueryResponseMsg) Header() *Header {
	return &Header{m.MsgSize, m.MsgType}
}

//----------------------------------------------------------------------
// REVOCATION_REVOKE
//----------------------------------------------------------------------

// RevocationRevokeMsg is a request to revoke a given key with PoW data
type RevocationRevokeMsg struct {
	MsgSize    uint16                `order:"big"`           // total size of message
	MsgType    uint16                `order:"big"`           // REVOCATION_REVOKE (638)
	Timestamp  util.AbsoluteTime     ``                      // Timestamp of revocation creation
	TTL        util.RelativeTime     ``                      // TTL of revocation
	PoWs       []uint64              `size:"32" order:"big"` // (Sorted) list of PoW values
	ZoneKeySig *crypto.ZoneSignature ``                      // public zone key (with signature) to be revoked
}

// NewRevocationRevokeMsg creates a new message for a given zone.
func NewRevocationRevokeMsg(zsig *crypto.ZoneSignature) *RevocationRevokeMsg {
	return &RevocationRevokeMsg{
		MsgSize:    364,
		MsgType:    REVOCATION_REVOKE,
		Timestamp:  util.AbsoluteTimeNow(),
		TTL:        util.RelativeTime{},
		PoWs:       make([]uint64, 32),
		ZoneKeySig: zsig,
	}
}

// String returns a human-readable representation of the message.
func (m *RevocationRevokeMsg) String() string {
	return fmt.Sprintf("RevocationRevokeMsg{zone=%s}", m.ZoneKeySig.ID())
}

// Header returns the message header in a separate instance.
func (m *RevocationRevokeMsg) Header() *Header {
	return &Header{m.MsgSize, m.MsgType}
}

//----------------------------------------------------------------------
// REVOCATION_REVOKE_RESPONSE
//----------------------------------------------------------------------

// RevocationRevokeResponseMsg is a response message for a revocation request
type RevocationRevokeResponseMsg struct {
	MsgSize uint16 `order:"big"` // total size of message
	MsgType uint16 `order:"big"` // REVOCATION_REVOKE_RESPONSE (639)
	Success uint32 `order:"big"` // Revoke successful? (0=no, 1=yes)
}

// NewRevocationRevokeResponseMsg creates a new response for a query.
func NewRevocationRevokeResponseMsg(success bool) *RevocationRevokeResponseMsg {
	status := 0
	if success {
		status = 1
	}
	return &RevocationRevokeResponseMsg{
		MsgSize: 8,
		MsgType: REVOCATION_QUERY_RESPONSE,
		Success: uint32(status),
	}
}

// String returns a human-readable representation of the message.
func (m *RevocationRevokeResponseMsg) String() string {
	return fmt.Sprintf("RevocationRevokeResponseMsg{success=%v}", m.Success == 1)
}

// Header returns the message header in a separate instance.
func (m *RevocationRevokeResponseMsg) Header() *Header {
	return &Header{m.MsgSize, m.MsgType}
}