Skip to content

Commit

Permalink
api: Validate length and patterns of IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
htdvisser committed Mar 21, 2019
1 parent f81c576 commit e0affeb
Show file tree
Hide file tree
Showing 18 changed files with 980 additions and 790 deletions.
14 changes: 7 additions & 7 deletions api/end_device.proto
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ message EndDeviceBrand {
}

message EndDeviceModel {
string brand_id = 1 [(gogoproto.customname) = "BrandID"];
string id = 2 [(gogoproto.customname) = "ID"];
string brand_id = 1 [(gogoproto.customname) = "BrandID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$", max_len: 36}];
string id = 2 [(gogoproto.customname) = "ID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$", max_len: 36}];
string name = 3;
}

// Identifies an end device model with version information.
message EndDeviceVersionIdentifiers {
string brand_id = 1 [(gogoproto.customname) = "BrandID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$|^$", max_len: 36}];
string model_id = 2 [(gogoproto.customname) = "ModelID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$|^$", max_len: 36}];
string brand_id = 1 [(gogoproto.customname) = "BrandID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$", max_len: 36}];
string model_id = 2 [(gogoproto.customname) = "ModelID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$", max_len: 36}];
string hardware_version = 3;
string firmware_version = 4;
}
Expand All @@ -146,7 +146,7 @@ message EndDeviceVersion {
// LoRaWAN PHY version.
PHYVersion lorawan_phy_version = 3 [(gogoproto.customname) = "LoRaWANPHYVersion", (validate.rules).enum.defined_only = true];
// ID of the frequency plan used by this device.
string frequency_plan_id = 4 [(gogoproto.customname) = "FrequencyPlanID"];
string frequency_plan_id = 4 [(gogoproto.customname) = "FrequencyPlanID", (validate.rules).string.max_len = 64];

// Photos contains file names of device photos.
repeated string photos = 5;
Expand Down Expand Up @@ -336,7 +336,7 @@ message EndDevice {
EndDeviceVersionIdentifiers version_ids = 7 [(gogoproto.customname) = "VersionIDs"];

// Default service profile. Stored in Entity Registry.
string service_profile_id = 8 [(gogoproto.customname) = "ServiceProfileID"];
string service_profile_id = 8 [(gogoproto.customname) = "ServiceProfileID", (validate.rules).string.max_len = 64];

// The address of the Network Server where this device is supposed to be registered.
// Stored in Entity Registry and Join Server.
Expand Down Expand Up @@ -377,7 +377,7 @@ message EndDevice {
PHYVersion lorawan_phy_version = 16 [(gogoproto.customname) = "LoRaWANPHYVersion", (validate.rules).enum.defined_only = true];
// ID of the frequency plan used by this device.
// Copied on creation from template identified by version_ids, if any or from the home Network Server device profile, if any.
string frequency_plan_id = 17 [(gogoproto.customname) = "FrequencyPlanID"];
string frequency_plan_id = 17 [(gogoproto.customname) = "FrequencyPlanID", (validate.rules).string.max_len = 64];
// Minimum frequency the device is capable of using (Hz). Stored in Network Server.
// Copied on creation from template identified by version_ids, if any or from the home Network Server device profile, if any.
uint64 min_frequency = 18;
Expand Down
10 changes: 5 additions & 5 deletions api/gateway.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ message GatewayBrand {
}

message GatewayModel {
string brand_id = 1 [(gogoproto.customname) = "BrandID"];
string id = 2 [(gogoproto.customname) = "ID"];
string brand_id = 1 [(gogoproto.customname) = "BrandID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$", max_len: 36}];
string id = 2 [(gogoproto.customname) = "ID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$", max_len: 36}];
string name = 3;
}

// Identifies an end device model with version information.
message GatewayVersionIdentifiers {
string brand_id = 1 [(gogoproto.customname) = "BrandID"];
string model_id = 2 [(gogoproto.customname) = "ModelID"];
string brand_id = 1 [(gogoproto.customname) = "BrandID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$", max_len: 36}];
string model_id = 2 [(gogoproto.customname) = "ModelID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$", max_len: 36}];
string hardware_version = 3;
string firmware_version = 4;
}
Expand Down Expand Up @@ -99,7 +99,7 @@ message Gateway {
string gateway_server_address = 9 [(validate.rules).string.pattern = "^(?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*(?:[A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])(?::[0-9]{1,5})?$|^$"];
bool auto_update = 10;
string update_channel = 11;
string frequency_plan_id = 12 [(gogoproto.customname) = "FrequencyPlanID"];
string frequency_plan_id = 12 [(gogoproto.customname) = "FrequencyPlanID", (validate.rules).string.max_len = 64];
repeated GatewayAntenna antennas = 13 [(gogoproto.nullable) = false];
// The status of this gateway may be publicly displayed.
bool status_public = 14;
Expand Down
2 changes: 1 addition & 1 deletion api/joinserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ option go_package = "go.thethings.network/lorawan-stack/pkg/ttnpb";

message SessionKeyRequest {
// Join Server issued identifier for the session keys.
bytes session_key_id = 1 [(gogoproto.customname) = "SessionKeyID"];
bytes session_key_id = 1 [(gogoproto.customname) = "SessionKeyID", (validate.rules).bytes.max_len = 2048];
// LoRaWAN DevEUI.
bytes dev_eui = 2 [(gogoproto.nullable) = false, (gogoproto.customtype) = "go.thethings.network/lorawan-stack/pkg/types.EUI64", (gogoproto.customname) = "DevEUI"];
}
Expand Down
5 changes: 3 additions & 2 deletions api/keys.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
syntax = "proto3";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/lyft/protoc-gen-validate/validate/validate.proto";

package ttn.lorawan.v3;

Expand All @@ -31,7 +32,7 @@ message KeyEnvelope {
// These are stored on the Join Server.
message RootKeys {
// Join Server issued identifier for the root keys.
string root_key_id = 1 [(gogoproto.customname) = "RootKeyID"];
string root_key_id = 1 [(gogoproto.customname) = "RootKeyID", (validate.rules).string.max_len = 2048];
// The (encrypted) Application Key.
KeyEnvelope app_key = 2;
// The (encrypted) Network Key.
Expand All @@ -45,7 +46,7 @@ message SessionKeys {

// Join Server issued identifier for the session keys.
// This ID can be used to request the keys from the Join Server in case the are lost.
bytes session_key_id = 1 [(gogoproto.customname) = "SessionKeyID"];
bytes session_key_id = 1 [(gogoproto.customname) = "SessionKeyID", (validate.rules).bytes.max_len = 2048];
// The (encrypted) Forwarding Network Session Integrity Key (or Network Session Key in 1.0 compatibility mode).
// This key is stored by the (forwarding) Network Server.
KeyEnvelope f_nwk_s_int_key = 2;
Expand Down
6 changes: 3 additions & 3 deletions api/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ message TxAcknowledgment {

message ApplicationUplink {
// Join Server issued identifier for the session keys used by this uplink.
bytes session_key_id = 1 [(gogoproto.customname) = "SessionKeyID"];
bytes session_key_id = 1 [(gogoproto.customname) = "SessionKeyID", (validate.rules).bytes.max_len = 2048];
uint32 f_port = 2 [(validate.rules).uint32.lte = 255];
uint32 f_cnt = 3;
bytes frm_payload = 4 [(gogoproto.customname) = "FRMPayload"];
Expand All @@ -172,7 +172,7 @@ message ApplicationLocation {

message ApplicationJoinAccept {
// Join Server issued identifier for the session keys negotiated in this join.
bytes session_key_id = 1 [(gogoproto.customname) = "SessionKeyID"];
bytes session_key_id = 1 [(gogoproto.customname) = "SessionKeyID", (validate.rules).bytes.max_len = 2048];
// Encrypted Application Session Key (if Join Server sent it to Network Server).
KeyEnvelope app_s_key = 2;
// Downlink messages in the queue that got invalidated because of the session change.
Expand All @@ -186,7 +186,7 @@ message ApplicationDownlink {
option (gogoproto.populate) = false;

// Join Server issued identifier for the session keys used by this downlink.
bytes session_key_id = 1 [(gogoproto.customname) = "SessionKeyID"];
bytes session_key_id = 1 [(gogoproto.customname) = "SessionKeyID", (validate.rules).bytes.max_len = 2048];
uint32 f_port = 2 [(validate.rules).uint32.lte = 255];
uint32 f_cnt = 3;
bytes frm_payload = 4 [(gogoproto.customname) = "FRMPayload"];
Expand Down
4 changes: 2 additions & 2 deletions api/user.proto
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ message DeleteInvitationRequest {

message UserSessionIdentifiers {
UserIdentifiers user_ids = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false, (validate.rules).message.required = true];
string session_id = 2 [(gogoproto.customname) = "SessionID"];
string session_id = 2 [(gogoproto.customname) = "SessionID", (validate.rules).string.max_len = 64];
}

message UserSession {
UserIdentifiers user_ids = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false, (validate.rules).message.required = true];
string session_id = 2 [(gogoproto.customname) = "SessionID"];
string session_id = 2 [(gogoproto.customname) = "SessionID", (validate.rules).string.max_len = 64];
google.protobuf.Timestamp created_at = 3 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
google.protobuf.Timestamp updated_at = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
google.protobuf.Timestamp expires_at = 5 [(gogoproto.stdtime) = true];
Expand Down
Loading

0 comments on commit e0affeb

Please sign in to comment.