Transfert hexadecimal instead of base64 when this is truly hexadecimal
This commit is contained in:
parent
4b59649168
commit
e70cc46be2
|
@ -145,8 +145,6 @@ func getServiceSpec(_ *config.Options, p httprouter.Params, body io.Reader) Resp
|
||||||
f.Required = true
|
f.Required = true
|
||||||
case "secret":
|
case "secret":
|
||||||
f.Secret = true
|
f.Secret = true
|
||||||
case "base64":
|
|
||||||
f.Type = "[]byte"
|
|
||||||
default:
|
default:
|
||||||
f.Label = kv[0]
|
f.Label = kv[0]
|
||||||
}
|
}
|
||||||
|
|
10
api/zones.go
10
api/zones.go
|
@ -33,7 +33,7 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/base64"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -58,8 +58,8 @@ func init() {
|
||||||
|
|
||||||
router.GET("/api/domains/:domain/zone/:zoneid/:subdomain", apiAuthHandler(domainHandler(zoneHandler(getZoneSubdomain))))
|
router.GET("/api/domains/:domain/zone/:zoneid/:subdomain", apiAuthHandler(domainHandler(zoneHandler(getZoneSubdomain))))
|
||||||
router.POST("/api/domains/:domain/zone/:zoneid/:subdomain", apiAuthHandler(domainHandler(zoneHandler(addZoneService))))
|
router.POST("/api/domains/:domain/zone/:zoneid/:subdomain", apiAuthHandler(domainHandler(zoneHandler(addZoneService))))
|
||||||
router.GET("/api/domains/:domain/zone/:zoneid/:subdomain/*serviceid", apiAuthHandler(domainHandler(zoneHandler(getZoneService))))
|
router.GET("/api/domains/:domain/zone/:zoneid/:subdomain/:serviceid", apiAuthHandler(domainHandler(zoneHandler(getZoneService))))
|
||||||
router.DELETE("/api/domains/:domain/zone/:zoneid/:subdomain/*serviceid", apiAuthHandler(domainHandler(zoneHandler(deleteZoneService))))
|
router.DELETE("/api/domains/:domain/zone/:zoneid/:subdomain/:serviceid", apiAuthHandler(domainHandler(zoneHandler(deleteZoneService))))
|
||||||
|
|
||||||
router.POST("/api/domains/:domain/import_zone", apiAuthHandler(domainHandler(importZone)))
|
router.POST("/api/domains/:domain/import_zone", apiAuthHandler(domainHandler(importZone)))
|
||||||
router.POST("/api/domains/:domain/view_zone/:zoneid", apiAuthHandler(domainHandler(zoneHandler(viewZone))))
|
router.POST("/api/domains/:domain/view_zone/:zoneid", apiAuthHandler(domainHandler(zoneHandler(viewZone))))
|
||||||
|
@ -157,7 +157,7 @@ func addZoneService(opts *config.Options, req *RequestResources, body io.Reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getZoneService(opts *config.Options, req *RequestResources, body io.Reader) Response {
|
func getZoneService(opts *config.Options, req *RequestResources, body io.Reader) Response {
|
||||||
serviceid, err := base64.StdEncoding.DecodeString(req.Ps.ByName("serviceid")[1:])
|
serviceid, err := hex.DecodeString(req.Ps.ByName("serviceid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return APIErrorResponse{
|
return APIErrorResponse{
|
||||||
err: err,
|
err: err,
|
||||||
|
@ -427,7 +427,7 @@ func updateZoneService(opts *config.Options, req *RequestResources, body io.Read
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteZoneService(opts *config.Options, req *RequestResources, body io.Reader) Response {
|
func deleteZoneService(opts *config.Options, req *RequestResources, body io.Reader) Response {
|
||||||
serviceid, err := base64.StdEncoding.DecodeString(req.Ps.ByName("serviceid")[1:])
|
serviceid, err := hex.DecodeString(req.Ps.ByName("serviceid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return APIErrorResponse{
|
return APIErrorResponse{
|
||||||
err: err,
|
err: err,
|
||||||
|
|
|
@ -88,14 +88,6 @@ export default {
|
||||||
get () {
|
get () {
|
||||||
if (this.specs.type === 'time.Duration') {
|
if (this.specs.type === 'time.Duration') {
|
||||||
return this.value / 1000000000
|
return this.value / 1000000000
|
||||||
} else if (this.specs.type === '[]uint8') {
|
|
||||||
const raw = atob(this.value)
|
|
||||||
let result = ''
|
|
||||||
for (let i = 0; i < raw.length; i++) {
|
|
||||||
const hex = raw.charCodeAt(i).toString(16)
|
|
||||||
result += (hex.length === 2 ? hex : '0' + hex)
|
|
||||||
}
|
|
||||||
return result.toUpperCase()
|
|
||||||
} else {
|
} else {
|
||||||
return this.value
|
return this.value
|
||||||
}
|
}
|
||||||
|
@ -105,14 +97,6 @@ export default {
|
||||||
this.$emit('input', value * 1000000000)
|
this.$emit('input', value * 1000000000)
|
||||||
} else if (this.specs.type === 'int' || this.specs.type === 'int8' || this.specs.type === 'int16' || this.specs.type === 'int32' || this.specs.type === 'int64' || this.specs.type === 'uint' || this.specs.type === 'uint8' || this.specs.type === 'uint16' || this.specs.type === 'uint32' || this.specs.type === 'uint64') {
|
} else if (this.specs.type === 'int' || this.specs.type === 'int8' || this.specs.type === 'int16' || this.specs.type === 'int32' || this.specs.type === 'int64' || this.specs.type === 'uint' || this.specs.type === 'uint8' || this.specs.type === 'uint16' || this.specs.type === 'uint32' || this.specs.type === 'uint64') {
|
||||||
this.$emit('input', parseInt(value, 10))
|
this.$emit('input', parseInt(value, 10))
|
||||||
} else if (this.specs.type === '[]uint8') {
|
|
||||||
let res = ''
|
|
||||||
if (value.length % 2) {
|
|
||||||
res = ('0' + value).match(/\w{2}/g).map(function (a) { return String.fromCharCode(parseInt(a, 16)) }).join('')
|
|
||||||
} else {
|
|
||||||
res = value.match(/\w{2}/g).map(function (a) { return String.fromCharCode(parseInt(a, 16)) }).join('')
|
|
||||||
}
|
|
||||||
this.$emit('input', btoa(res))
|
|
||||||
} else {
|
} else {
|
||||||
this.$emit('input', value)
|
this.$emit('input', value)
|
||||||
}
|
}
|
||||||
|
|
58
model/hexastring.go
Normal file
58
model/hexastring.go
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
// Copyright or © or Copr. happyDNS (2020)
|
||||||
|
//
|
||||||
|
// contact@happydns.org
|
||||||
|
//
|
||||||
|
// This software is a computer program whose purpose is to provide a modern
|
||||||
|
// interface to interact with DNS systems.
|
||||||
|
//
|
||||||
|
// This software is governed by the CeCILL license under French law and abiding
|
||||||
|
// by the rules of distribution of free software. You can use, modify and/or
|
||||||
|
// redistribute the software under the terms of the CeCILL license as
|
||||||
|
// circulated by CEA, CNRS and INRIA at the following URL
|
||||||
|
// "http://www.cecill.info".
|
||||||
|
//
|
||||||
|
// As a counterpart to the access to the source code and rights to copy, modify
|
||||||
|
// and redistribute granted by the license, users are provided only with a
|
||||||
|
// limited warranty and the software's author, the holder of the economic
|
||||||
|
// rights, and the successive licensors have only limited liability.
|
||||||
|
//
|
||||||
|
// In this respect, the user's attention is drawn to the risks associated with
|
||||||
|
// loading, using, modifying and/or developing or reproducing the software by
|
||||||
|
// the user in light of its specific status of free software, that may mean
|
||||||
|
// that it is complicated to manipulate, and that also therefore means that it
|
||||||
|
// is reserved for developers and experienced professionals having in-depth
|
||||||
|
// computer knowledge. Users are therefore encouraged to load and test the
|
||||||
|
// software's suitability as regards their requirements in conditions enabling
|
||||||
|
// the security of their systems and/or data to be ensured and, more generally,
|
||||||
|
// to use and operate it in the same conditions as regards security.
|
||||||
|
//
|
||||||
|
// The fact that you are presently reading this means that you have had
|
||||||
|
// knowledge of the CeCILL license and that you accept its terms.
|
||||||
|
|
||||||
|
package happydns
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HexaString []byte
|
||||||
|
|
||||||
|
func (hs *HexaString) MarshalJSON() (dst []byte, err error) {
|
||||||
|
dst = make([]byte, hex.EncodedLen(len(*hs)))
|
||||||
|
hex.Encode(dst, *hs)
|
||||||
|
dst = append([]byte{'"'}, dst...)
|
||||||
|
dst = append(dst, '"')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (hs *HexaString) UnmarshalJSON(b []byte) (err error) {
|
||||||
|
if len(b) == 0 || b[0] != '"' || b[len(b)-1] != '"' {
|
||||||
|
return errors.New("Expected JSON string")
|
||||||
|
}
|
||||||
|
|
||||||
|
*hs = make([]byte, hex.DecodedLen(len(b)-2))
|
||||||
|
_, err = hex.Decode(*hs, b[1:len(b)-1])
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
|
@ -53,7 +53,7 @@ type ServiceMeta struct {
|
||||||
Type string `json:"_svctype"`
|
Type string `json:"_svctype"`
|
||||||
|
|
||||||
// Id is the Service's identifier.
|
// Id is the Service's identifier.
|
||||||
Id []byte `json:"_id,omitempty"`
|
Id HexaString `json:"_id,omitempty"`
|
||||||
|
|
||||||
// OwnerId is the User's identifier for the current Service.
|
// OwnerId is the User's identifier for the current Service.
|
||||||
OwnerId int64 `json:"_ownerid,omitempty"`
|
OwnerId int64 `json:"_ownerid,omitempty"`
|
||||||
|
|
|
@ -44,9 +44,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type OpenPGP struct {
|
type OpenPGP struct {
|
||||||
Username string `json:"username,omitempty"`
|
Username string `json:"username,omitempty"`
|
||||||
Identifier string `json:"identifier,omitempty"`
|
Identifier string `json:"identifier,omitempty"`
|
||||||
PublicKey []byte `json:"pubkey"`
|
PublicKey happydns.HexaString `json:"pubkey"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OpenPGP) GetNbResources() int {
|
func (s *OpenPGP) GetNbResources() int {
|
||||||
|
@ -65,7 +65,7 @@ func (s *OpenPGP) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR
|
||||||
|
|
||||||
rrs = append(rrs, &dns.OPENPGPKEY{
|
rrs = append(rrs, &dns.OPENPGPKEY{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
Name: fmt.Sprintf("_%s._openpgpkey.%s", s.Identifier, domain),
|
Name: fmt.Sprintf("%s._openpgpkey.%s", s.Identifier, domain),
|
||||||
Rrtype: dns.TypeOPENPGPKEY,
|
Rrtype: dns.TypeOPENPGPKEY,
|
||||||
Class: dns.ClassINET,
|
Class: dns.ClassINET,
|
||||||
Ttl: ttl,
|
Ttl: ttl,
|
||||||
|
@ -77,12 +77,12 @@ func (s *OpenPGP) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR
|
||||||
}
|
}
|
||||||
|
|
||||||
type SMimeCert struct {
|
type SMimeCert struct {
|
||||||
Username string `json:"username,omitempty"`
|
Username string `json:"username,omitempty"`
|
||||||
Identifier string `json:"identifier,omitempty"`
|
Identifier string `json:"identifier,omitempty"`
|
||||||
CertUsage uint8 `json:"certusage"`
|
CertUsage uint8 `json:"certusage"`
|
||||||
Selector uint8 `json:"selector"`
|
Selector uint8 `json:"selector"`
|
||||||
MatchingType uint8 `json:"matchingtype"`
|
MatchingType uint8 `json:"matchingtype"`
|
||||||
Certificate []byte `json:"certificate"`
|
Certificate happydns.HexaString `json:"certificate"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SMimeCert) GetNbResources() int {
|
func (s *SMimeCert) GetNbResources() int {
|
||||||
|
@ -101,7 +101,7 @@ func (s *SMimeCert) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.
|
||||||
|
|
||||||
rrs = append(rrs, &dns.SMIMEA{
|
rrs = append(rrs, &dns.SMIMEA{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
Name: fmt.Sprintf("_%s._smimecert.%s", s.Identifier, domain),
|
Name: fmt.Sprintf("%s._smimecert.%s", s.Identifier, domain),
|
||||||
Rrtype: dns.TypeSMIMEA,
|
Rrtype: dns.TypeSMIMEA,
|
||||||
Class: dns.ClassINET,
|
Class: dns.ClassINET,
|
||||||
Ttl: ttl,
|
Ttl: ttl,
|
||||||
|
|
|
@ -44,12 +44,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type TLSA struct {
|
type TLSA struct {
|
||||||
Proto string `json:"proto" happydns:"label=Protocol,description=Protocol used to establish the connection.,choices=tcp;udp"`
|
Proto string `json:"proto" happydns:"label=Protocol,description=Protocol used to establish the connection.,choices=tcp;udp"`
|
||||||
Port uint16 `json:"port" happydns:"label=Service Port,description=Port number where people will establish the connection."`
|
Port uint16 `json:"port" happydns:"label=Service Port,description=Port number where people will establish the connection."`
|
||||||
CertUsage uint8 `json:"certusage"`
|
CertUsage uint8 `json:"certusage"`
|
||||||
Selector uint8 `json:"selector"`
|
Selector uint8 `json:"selector"`
|
||||||
MatchingType uint8 `json:"matchingtype"`
|
MatchingType uint8 `json:"matchingtype"`
|
||||||
Certificate []byte `json:"certificate"`
|
Certificate happydns.HexaString `json:"certificate"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TLSAs struct {
|
type TLSAs struct {
|
||||||
|
|
|
@ -48,7 +48,7 @@ type DDNSServer struct {
|
||||||
Server string `json:"server,omitempty" happydns:"label=Server,placeholder=127.0.0.1"`
|
Server string `json:"server,omitempty" happydns:"label=Server,placeholder=127.0.0.1"`
|
||||||
KeyName string `json:"keyname,omitempty" happydns:"label=Key Name,placeholder=ddns.,required"`
|
KeyName string `json:"keyname,omitempty" happydns:"label=Key Name,placeholder=ddns.,required"`
|
||||||
KeyAlgo string `json:"algorithm,omitempty" happydns:"label=Key Algorithm,default=hmac-sha256.,choices=hmac-md5.sig-alg.reg.int.;hmac-sha1.;hmac-sha224.;hmac-sha256.;hmac-sha384.;hmac-sha512.,required"`
|
KeyAlgo string `json:"algorithm,omitempty" happydns:"label=Key Algorithm,default=hmac-sha256.,choices=hmac-md5.sig-alg.reg.int.;hmac-sha1.;hmac-sha224.;hmac-sha256.;hmac-sha384.;hmac-sha512.,required"`
|
||||||
KeyBlob []byte `json:"keyblob,omitempty" happydns:"label=Secret Key,placeholder=a0b1c2d3e4f5==,required,secret,base64"`
|
KeyBlob []byte `json:"keyblob,omitempty" happydns:"label=Secret Key,placeholder=a0b1c2d3e4f5==,required,secret"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DDNSServer) serverURI() string {
|
func (s *DDNSServer) serverURI() string {
|
||||||
|
|
|
@ -108,8 +108,6 @@ func GenSourceField(field reflect.StructField) (f *SourceField) {
|
||||||
f.Required = true
|
f.Required = true
|
||||||
case "secret":
|
case "secret":
|
||||||
f.Secret = true
|
f.Secret = true
|
||||||
case "base64":
|
|
||||||
f.Type = "[]byte"
|
|
||||||
default:
|
default:
|
||||||
f.Label = kv[0]
|
f.Label = kv[0]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user