5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 21:26:21 +00:00

Detectar cuando el servicio oculto es opcional

This commit is contained in:
f 2021-08-07 18:59:23 -03:00
parent 45559ad58f
commit 70c8bcbcd1
4 changed files with 22 additions and 7 deletions

View file

@ -16,7 +16,7 @@ module Api
#
# @return [Array] lista de nombres de sitios sin onion aun
def hidden_services
render json: DeployHiddenService.where(values: nil).includes(:site).pluck(:name)
render json: DeployHiddenService.temporary.includes(:site).pluck(:name)
end
# Tor va a enviar el onion junto con el nombre del sitio y tenemos
@ -28,7 +28,7 @@ module Api
site = Site.find_by(name: params[:name])
if site
usuarie = GitAuthor.new email: 'tor@' + Site.domain, name: 'Tor'
usuarie = GitAuthor.new email: "tor@#{Site.domain}", name: 'Tor'
service = SiteService.new site: site, usuarie: usuarie,
params: params
service.add_onion

View file

@ -5,6 +5,12 @@
class DeployHiddenService < DeployWww
validates :hostname, format: { with: /\A[a-z2-7]{56}.onion\z/ }
# Sufijo para todos los dominios temporales.
TEMPORARY_SUFFIX = 'temporary'
# Traer todos los servicios ocultos temporales.
scope :temporary, -> { where("hostname not like '#{TEMPORARY_SUFFIX}%'") }
# Los servicios ocultos son su propio transporte cifrado y
# autenticado.
#
@ -19,7 +25,14 @@ class DeployHiddenService < DeployWww
#
# @return [String]
def default_hostname
"temporal#{random_base32}.onion"
"#{TEMPORARY_SUFFIX}#{random_base32}.onion"
end
# Detecta si es una dirección temporal.
#
# @return [Boolean]
def temporary?
hostname.start_with? TEMPORARY_SUFFIX
end
private
@ -32,8 +45,9 @@ class DeployHiddenService < DeployWww
#
# @see {https://github.com/stesla/base32/blob/master/lib/base32.rb}
# @see {https://github.com/stesla/base32/blob/master/LICENSE}
def random_base32(length = 48)
def random_base32(length = nil)
table = 'abcdefghijklmnopqrstuvwxyz234567'
length ||= 56 - TEMPORARY_SUFFIX.length
OpenSSL::Random.random_bytes(length).each_byte.map do |b|
table[b % 32]

View file

@ -17,6 +17,7 @@
= sanitize_markdown t('.help', public_url: site.deploy_local.url),
tags: %w[p strong em a]
= sanitize_markdown t('.help_2', url: deploy.object.url),
tags: %w[p strong em a]
- unless deploy.object.temporary?
= sanitize_markdown t('.help_2', url: deploy.object.url),
tags: %w[p strong em a]
%hr/

View file

@ -20,7 +20,7 @@ class DeployHiddenServiceTest < ActiveSupport::TestCase
end
test 'los hostnames pueden ser temporales' do
assert @deploy_hidden.hostname.start_with? 'temporal'
assert @deploy_hidden.hostname.start_with? 'temporary'
end
test 'el hostname tiene que ser único' do