1
0
Fork 0

Add column RSAPublicKey#public_key_der

This commit is contained in:
Alex Kotov 2019-09-13 17:52:03 +05:00
parent ae921e3cab
commit dfee0e29ca
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
6 changed files with 19 additions and 1 deletions

View File

@ -22,6 +22,7 @@ private
sha256: Digest::SHA256.hexdigest(pkey.public_key.to_der),
public_key_pem: pkey.public_key.to_pem.freeze,
public_key_der: pkey.public_key.to_der.freeze,
private_key_pem: pkey.to_pem.freeze,
}
end

View File

@ -9,6 +9,8 @@ class RSAPublicKey < ApplicationRecord
validates :public_key_pem, presence: true
validates :public_key_der, presence: true
validates :bits, inclusion: { in: [2048, 4096] }
validates :sha1,

View File

@ -7,7 +7,8 @@ class CreateX509Tables < ActiveRecord::Migration[6.0]
create_table :rsa_public_keys do |t|
t.timestamps null: false
t.text :public_key_pem, null: false
t.text :public_key_pem, null: false
t.binary :public_key_der, null: false
t.binary :private_key_pem_iv
t.binary :private_key_pem_ciphertext
@ -17,6 +18,7 @@ class CreateX509Tables < ActiveRecord::Migration[6.0]
t.string :sha256, null: false
t.index :public_key_pem, unique: true
t.index :public_key_der, unique: true
t.index :sha1, unique: true
t.index :sha256, unique: true
end

View File

@ -730,6 +730,7 @@ CREATE TABLE public.rsa_public_keys (
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
public_key_pem text NOT NULL,
public_key_der bytea NOT NULL,
private_key_pem_iv bytea,
private_key_pem_ciphertext bytea,
bits integer NOT NULL,
@ -1459,6 +1460,13 @@ CREATE INDEX index_relationships_on_role ON public.relationships USING btree (ro
CREATE INDEX index_relationships_on_status ON public.relationships USING btree (status);
--
-- Name: index_rsa_public_keys_on_public_key_der; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_rsa_public_keys_on_public_key_der ON public.rsa_public_keys USING btree (public_key_der);
--
-- Name: index_rsa_public_keys_on_public_key_pem; Type: INDEX; Schema: public; Owner: -
--

View File

@ -3,6 +3,7 @@
FactoryBot.define do
factory :rsa_public_key do
public_key_pem { OpenSSL::PKey::RSA.new(bits).public_key.to_pem }
public_key_der { OpenSSL::PKey::RSA.new(bits).public_key.to_der }
bits { [2048, 4096].sample }
sha1 { Digest::SHA1.hexdigest SecureRandom.hex }
sha256 { Digest::SHA256.hexdigest SecureRandom.hex }

View File

@ -9,6 +9,10 @@ RSpec.describe RSAPublicKey do
it { is_expected.to validate_presence_of :public_key_pem }
end
describe '#public_key_der' do
it { is_expected.to validate_presence_of :public_key_der }
end
describe '#bits' do
it { is_expected.to validate_inclusion_of(:bits).in_array([2048, 4096]) }
end