mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-15 17:03:45 +02:00
Certificate self-test passes now.
This commit is contained in:
parent
fdafddafa0
commit
24ab618123
4 changed files with 14 additions and 29 deletions
|
@ -20,8 +20,10 @@
|
||||||
#include "Network.hpp"
|
#include "Network.hpp"
|
||||||
#include "Spinlock.hpp"
|
#include "Spinlock.hpp"
|
||||||
|
|
||||||
|
// The number of buckets must be a power of two.
|
||||||
#define ZT_TINYMAP_BUCKETS 1024
|
#define ZT_TINYMAP_BUCKETS 1024
|
||||||
#define ZT_TINYMAP_BUCKETS_MASK 1023
|
|
||||||
|
#define ZT_TINYMAP_BUCKETS_MASK (ZT_TINYMAP_BUCKETS - 1)
|
||||||
#define ZT_TINYMAP_LOCKED_POINTER (~((uintptr_t)0))
|
#define ZT_TINYMAP_LOCKED_POINTER (~((uintptr_t)0))
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
|
@ -19,6 +19,7 @@ use std::pin::Pin;
|
||||||
use std::ptr::{copy_nonoverlapping, null, null_mut};
|
use std::ptr::{copy_nonoverlapping, null, null_mut};
|
||||||
|
|
||||||
use num_derive::{FromPrimitive, ToPrimitive};
|
use num_derive::{FromPrimitive, ToPrimitive};
|
||||||
|
#[allow(unused_imports)]
|
||||||
use num_traits::{FromPrimitive, ToPrimitive};
|
use num_traits::{FromPrimitive, ToPrimitive};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -671,28 +672,19 @@ impl Certificate {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use num_traits::FromPrimitive;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generate_certificate_unique_id() {
|
fn generate_key_pair() {
|
||||||
let (pubk, privk) = Certificate::new_key_pair(CertificatePublicKeyAlgorithm::ECDSANistP384).ok().unwrap();
|
let (pubk, privk) = Certificate::new_key_pair(CertificatePublicKeyAlgorithm::ECDSANistP384).ok().unwrap();
|
||||||
println!("certificate unique ID public: {}", hex::encode(pubk.as_ref()).as_str());
|
println!("key pair public: {}", hex::encode(pubk).as_str());
|
||||||
println!("certificate unique ID private: {}", hex::encode(privk.as_ref()).as_str());
|
println!("key pair private: {}", hex::encode(privk).as_str());
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn enum_from_primitive() {
|
|
||||||
let ce = CertificateError::from_i32(-2 as i32);
|
|
||||||
assert!(ce.is_some());
|
|
||||||
let ce = ce.unwrap();
|
|
||||||
assert!(ce == CertificateError::InvalidIdentity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cert() {
|
fn cert() {
|
||||||
let (issuer_pubk, issuer_privk) = Certificate::new_key_pair(CertificatePublicKeyAlgorithm::ECDSANistP384).ok().unwrap();
|
let (issuer_pubk, issuer_privk) = Certificate::new_key_pair(CertificatePublicKeyAlgorithm::ECDSANistP384).ok().unwrap();
|
||||||
let (pubk, privk) = Certificate::new_key_pair(CertificatePublicKeyAlgorithm::ECDSANistP384).ok().unwrap();
|
let (pubk, _) = Certificate::new_key_pair(CertificatePublicKeyAlgorithm::ECDSANistP384).ok().unwrap();
|
||||||
let (unique_id, unique_id_private) = Certificate::new_key_pair(CertificatePublicKeyAlgorithm::ECDSANistP384).ok().unwrap();
|
let (_, unique_id_private) = Certificate::new_key_pair(CertificatePublicKeyAlgorithm::ECDSANistP384).ok().unwrap();
|
||||||
let id0 = Identity::new_generate(IdentityType::Curve25519).ok().unwrap();
|
let id0 = Identity::new_generate(IdentityType::Curve25519).ok().unwrap();
|
||||||
|
|
||||||
let mut cert = Certificate{
|
let mut cert = Certificate{
|
||||||
|
@ -703,7 +695,7 @@ mod tests {
|
||||||
subject: CertificateSubject::new(),
|
subject: CertificateSubject::new(),
|
||||||
issuer: CertificateSerialNo::new(),
|
issuer: CertificateSerialNo::new(),
|
||||||
issuer_public_key: issuer_pubk,
|
issuer_public_key: issuer_pubk,
|
||||||
public_key: pubk,
|
public_key: pubk.clone(),
|
||||||
extended_attributes: Vec::new(),
|
extended_attributes: Vec::new(),
|
||||||
max_path_length: 123,
|
max_path_length: 123,
|
||||||
signature: Vec::new()
|
signature: Vec::new()
|
||||||
|
@ -735,29 +727,22 @@ mod tests {
|
||||||
host: String::from("zerotier.com")
|
host: String::from("zerotier.com")
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("{}", cert.to_json().as_str());
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let cert_capi = cert.to_capi();
|
let cert_capi = cert.to_capi();
|
||||||
let cert2 = Certificate::new_from_capi(&cert_capi.certificate);
|
let cert2 = Certificate::new_from_capi(&cert_capi.certificate);
|
||||||
assert!(cert == cert2);
|
assert!(cert == cert2);
|
||||||
//println!("{}", cert2.to_json().as_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let cert2 = Certificate::new_from_json(cert.to_json().as_str());
|
|
||||||
assert!(cert2.is_ok());
|
|
||||||
assert!(cert2.ok().unwrap() == cert);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let csr = cert.subject.new_csr(pubk.as_ref(), Some(unique_id_private.as_ref()));
|
let csr = cert.subject.new_csr(pubk.as_ref(), Some(unique_id_private.as_ref()));
|
||||||
assert!(csr.is_ok());
|
assert!(csr.is_ok());
|
||||||
let csr = csr.ok().unwrap();
|
let csr = csr.ok().unwrap();
|
||||||
|
|
||||||
let mut csr_decoded = Certificate::new_from_bytes(csr.as_ref(), false);
|
let csr_decoded = Certificate::new_from_bytes(csr.as_ref(), false);
|
||||||
assert!(csr_decoded.is_ok());
|
assert!(csr_decoded.is_ok());
|
||||||
let mut csr_decoded = csr_decoded.ok().unwrap();
|
let mut csr_decoded = csr_decoded.ok().unwrap();
|
||||||
|
|
||||||
|
csr_decoded.validity = cert.validity;
|
||||||
|
|
||||||
let cert_signed = csr_decoded.sign(&cert.issuer, issuer_privk.as_ref());
|
let cert_signed = csr_decoded.sign(&cert.issuer, issuer_privk.as_ref());
|
||||||
assert!(cert_signed.is_ok());
|
assert!(cert_signed.is_ok());
|
||||||
let cert_signed = cert_signed.ok().unwrap();
|
let cert_signed = cert_signed.ok().unwrap();
|
||||||
|
|
|
@ -49,7 +49,7 @@ impl Identity {
|
||||||
type_: FromPrimitive::from_i32(idt as i32).unwrap(),
|
type_: FromPrimitive::from_i32(idt as i32).unwrap(),
|
||||||
address: Address(a),
|
address: Address(a),
|
||||||
capi: id,
|
capi: id,
|
||||||
requires_delete: requires_delete,
|
requires_delete,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,6 @@ impl<'de> serde::Deserialize<'de> for Identity {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use crate::StateObjectType::IdentitySecret;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn identity() {
|
fn identity() {
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
*/
|
*/
|
||||||
/****/
|
/****/
|
||||||
|
|
||||||
use std::io::Write;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue