Add columns RSAPublicKey#sha1, #sha256
This commit is contained in:
parent
33798046f4
commit
abcdea4e43
5 changed files with 41 additions and 1 deletions
|
@ -11,6 +11,14 @@ class RSAPublicKey < ApplicationRecord
|
|||
|
||||
validates :bits, inclusion: { in: [2048, 4096] }
|
||||
|
||||
validates :sha1,
|
||||
presence: true,
|
||||
uniqueness: { case_sensitive: false }
|
||||
|
||||
validates :sha256,
|
||||
presence: true,
|
||||
uniqueness: { case_sensitive: false }
|
||||
|
||||
###########
|
||||
# Methods #
|
||||
###########
|
||||
|
|
|
@ -12,9 +12,13 @@ class CreateX509Tables < ActiveRecord::Migration[6.0]
|
|||
t.binary :private_key_pem_iv
|
||||
t.binary :private_key_pem_ciphertext
|
||||
|
||||
t.integer :bits, null: false
|
||||
t.integer :bits, null: false
|
||||
t.string :sha1, null: false
|
||||
t.string :sha256, null: false
|
||||
|
||||
t.index :public_key_pem, unique: true
|
||||
t.index :sha1, unique: true
|
||||
t.index :sha256, unique: true
|
||||
end
|
||||
|
||||
constraint :rsa_public_keys, :bits, <<~SQL
|
||||
|
|
|
@ -733,6 +733,8 @@ CREATE TABLE public.rsa_public_keys (
|
|||
private_key_pem_iv bytea,
|
||||
private_key_pem_ciphertext bytea,
|
||||
bits integer NOT NULL,
|
||||
sha1 character varying NOT NULL,
|
||||
sha256 character varying NOT NULL,
|
||||
CONSTRAINT bits CHECK ((bits = ANY (ARRAY[2048, 4096])))
|
||||
);
|
||||
|
||||
|
@ -1464,6 +1466,20 @@ CREATE INDEX index_relationships_on_status ON public.relationships USING btree (
|
|||
CREATE UNIQUE INDEX index_rsa_public_keys_on_public_key_pem ON public.rsa_public_keys USING btree (public_key_pem);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_rsa_public_keys_on_sha1; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX index_rsa_public_keys_on_sha1 ON public.rsa_public_keys USING btree (sha1);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_rsa_public_keys_on_sha256; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX index_rsa_public_keys_on_sha256 ON public.rsa_public_keys USING btree (sha256);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_sessions_on_account_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
|
|
@ -4,5 +4,7 @@ FactoryBot.define do
|
|||
factory :rsa_public_key do
|
||||
public_key_pem { OpenSSL::PKey::RSA.new(bits).public_key.to_pem }
|
||||
bits { [2048, 4096].sample }
|
||||
sha1 { Digest::SHA1.hexdigest SecureRandom.hex }
|
||||
sha256 { Digest::SHA256.hexdigest SecureRandom.hex }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,6 +13,16 @@ RSpec.describe RSAPublicKey do
|
|||
it { is_expected.to validate_inclusion_of(:bits).in_array([2048, 4096]) }
|
||||
end
|
||||
|
||||
describe '#sha1' do
|
||||
it { is_expected.to validate_presence_of :sha1 }
|
||||
it { is_expected.to validate_uniqueness_of(:sha1).case_insensitive }
|
||||
end
|
||||
|
||||
describe '#sha256' do
|
||||
it { is_expected.to validate_presence_of :sha256 }
|
||||
it { is_expected.to validate_uniqueness_of(:sha256).case_insensitive }
|
||||
end
|
||||
|
||||
describe '#private_key_pem_iv' do
|
||||
it { is_expected.not_to validate_presence_of :private_key_pem_iv }
|
||||
end
|
||||
|
|
Reference in a new issue