windows command line csr file certreq.exe output bad format on Subject ,Issue to, and issue by - command

Windows command line CSR file
`certreq.exe -new C:\Certs\template.inf C:\Certs\mydomain.txt.csr`
returns:
bad format on Subject ,Issue to, and issue by this format
The template.inf has
Subject = "CN=mydomain.com, OU=IT, O=My Company, L=my city, S=my state, C=US
I get this on
Issue to: CN=mydomain.com, OU=IT, O=My Company, L=my city, S=my state, C=US in 1 line.
same for
issue by: CN=mydomain.com, OU=IT, O=My Company, L=my city, S=my state, C=US
also
Subject : CN=mydomain.com, OU=IT, O=My Company, L=my city, S=my state, C=US
With the IIS server certificates mmc. I get the below, the desired result
CN = mydomain.com
OU = IT
O = My Company
L = my city
S = my state
C = US
All the documentation says to put it all in 1 line in the template file.
Can some one please advice?

Take the following *.inf as source template to generate a web server certificate:
[Version]
Signature="$Windows NT$"
[Strings]
szOID_SAN = "2.5.29.17"
szOID_ENHANCED_KEY_USAGE = "2.5.29.37"
szOID_PKIX_KP_SERVER_AUTH = "1.3.6.1.5.5.7.3.1"
[NewRequest]
Exportable=False
SMIME=False
Hashalgorithm=SHA256
KeyLength=2048
KeySpec = AT_KEYEXCHANGE
KeyUsage = "CERT_DIGITAL_SIGNATURE_KEY_USAGE | CERT_KEY_ENCIPHERMENT_KEY_USAGE"
RequestType=PKCS10; PKCS10 or CMC
Subject="CN=mydomain.com, OU=IT, O=My Company, L=my city, S=my state, C=US"
ProviderName="Microsoft Software Key Storage Provider"
MachineKeySet=True
[Extensions]
%szOID_SAN%="{text}"
_continue_ = "DNS=mydomain.com&"
%szOID_ENHANCED_KEY_USAGE%="{text}"
_continue_ = "%szOID_PKIX_KP_SERVER_AUTH%,"
I used your subject and for better compatibility with browsers I also added the CN value as DNS Host Name to the subject alternative name.
As MachineKeySet is set to True the following command must be run with administrative privileges:
& certreq.exe -New ".\Template.inf" "CertificateSigningRequest.p10"

Related

Retrieve the valid Party ids from the Latest record DataFrame based on lookup from Invalid Party DataFrame

Input:
1.Latest Party Records (Primary Key : prty_id, Latest Record identified using : lst_upd_dt)
prty_id country role lst_upd_dt
P1 IN Partner 2022/03/01
P2 JP VSI 2022/01/01
P3 CS Vendor 2021/05/18
P4 US Customer 2022/03/12
P5 CA Partner 2022/10/01
P6 IN Customer 2019/03/01
P7 CN Vendor 2022/02/01
P8 BZ Vendor 2020/09/15
Invalid party id:
Invalid Party Id Records
prty_id
P1
P7
P4
Required output is:
Valid Party Ids from Latest Record.
prty_id country role lst_upd_dt
P2 JP VSI 2022/01/01
P3 CS Vendor 2021/05/18
P5 CA Partner 2022/10/01
P6 IN Customer 2019/03/01
P8 BZ Vendor 2020/09/15
I am done the code using filter condition like below:
val valid_id=new_part_data.filter($"prty_id"=!="P1")
.filter($"prty_id"=!="P4").filter($"prty_id"=!="P7").show()
But requirement is:
Invalid parties should not be filtered based on hard coding, they should be either from parameter file. how to use this to get the output?
You can do that using a left anti join:
val valid_id = new_part_data
.join(
right = invalid_id,
usingColumns = Seq("prty_id"),
joinType = "left_anti"
)
valid_id.show()
// +-------+-------+--------+----------+
// |prty_id|country| role|lst_upd_dt|
// +-------+-------+--------+----------+
// | P2| JP| VSI|2022/01/01|
// | P3| CS| Vendor|2021/05/18|
// | P5| CA| Partner|2022/10/01|
// | P6| IN|Customer|2019/03/01|
// | P8| BZ| Vendor|2020/09/15|
// +-------+-------+--------+----------+
The left anti join will keep rows from the left dataframe (new_part_data), for which the right dataframe (invalid_id, containing the invalid partie ids) do not have a corresponding value in the column prty_id.

Many to one where the one can be one of two different fields

I've had a look at similar posts on one to many and many to one relationships but I just can't find what I'm looking for. I have 2 tables. The first (vm) contains details of virtual machines. The vms are clustered in pairs and the second table (cluster) has details of the cluster. The set up is as follows:
vm table cluster table
vmId clusterId
ipaddress primaryId
macaddress secondaryId
The relationship is that the vm.vmId can be a match to either cluster.primaryId or cluster.secondaryId. With only an ipaddress I want to be able to get the full cluster details as follows:
clusterid vmId ipaddress macaddress
c1 v1 10.0.10.10 AA:BB:CC:DD:10:11
C1 v2 10.0.10.11 AA:BB:CC:DD:10:12
and that's my problem. With just the ipaddress I can find the vmId and with that I can get the cluster, but I can't then work out how to use the non matching id in the cluster table to get the other vm details. I've tried variables and unions etc., but I must be doing something wrong because I keep coming up blank. I'm looking for a single select statement that will provide the required result. Can anyone suggest a solution please?
First find the cluster(s) with given IP:
select *
from cluster
where exists (
select 1
from vm
where
(vm.vmId = cluster.primaryId or vm.vmId = cluster.secondaryId) and
wm.ipaddress = '127.0.0.1');
Then join this with vm table in the same way:
with clusters as (
select *
from cluster
where exists (
select 1
from vm
where
(vm.vmId = cluster.primaryId or vm.vmId = cluster.secondaryId) and
wm.ipaddress = '127.0.0.1'))
select *
from clusters join vm on (vm.vmId = clusters.primaryId or vm.vmId = clusters.secondaryId);
This is probably what you are looking for, but realize that the vmIds will appear twice, once under the primary cluster, and another under the secondary cluster.
SELECT clusterid, vmId, ipaddress, macaddress
FROM vm
JOIN cluster
ON vm.vmId = cluster.primaryId
UNION ALL
SELECT clusterid, vmId, ipaddress, macaddress
FROM vm
JOIN cluster
ON vm.vmId = cluster.secondaryId
The above can be reduced to:
SELECT clusterid, vmId, ipaddress, macaddress
FROM vm
JOIN cluster
ON (vm.vmId = cluster.primaryId OR vm.vmId = cluster.secondaryId)
If you want to filter the result:
SELECT clusterid, vmId, ipaddress, macaddress
FROM vm
JOIN cluster
ON (vm.vmId = cluster.primaryId OR vm.vmId = cluster.secondaryId)
WHERE ipaddress = '10.0.10.10'
With your help I did finally manage to get the answer I was looking for. With a little modification of your suggestions I finally came up with this.
with clusters as (
select clusterId
from cluster
where exists (
select 1
from vm
where
(vm.vmId = cluster.primaryId or vm.vmId = cluster.secondaryId) and
wm.ipaddress = '10.0.10.10'))
select clusterId, vmId, ipaddress, macaddress
from vm
join cluster on (vm.vmId = cluster.primaryId or vm.vmId = cluster.secondaryId)
where cluster.clusterId = (select * from clusters)
Produced exactly the result I was looking for. Thanks everyone for your assistence.

How to fetch doctype eg: address or tax rule

I want to fetch the doctype. How do I do this? I want to add a separate column which will give doctype such as sales order, purchase order etc. The first line gives me error what query should be fired. Please help I am new to ERP Next.
SELECT
AD.ref_doctype AS “Doctype:Link/User:120”,
AD.name AS “Doc#:Link/Doctype:120”,
AD.owner AS “Created By:Link/User:120”,
AD.modified AS “Modified On:Date:120”
FROM tabAddress AS AD
WHERE
DATEDIFF(now(),AD.modified) BETWEEN 1 AND 30
UNION ALL
SELECT
TR.name AS “Doc#:Link/Doctype:120”,
TR.owner AS “Created By:Link/User:120”,
TR.modified AS “Modified On:Date:120”
FROM tabTax Rule AS TR
WHERE
DATEDIFF(now(),TR.modified) BETWEEN 1 AND 30
UNION ALL
SELECT
IT.name AS “Doc#:Link/Doctype:120”,
IT.owner AS “Created By:Link/User:120”,
IT.modified AS “Modified On:Date:120”
FROM tabItem AS IT
WHERE
DATEDIFF(now(),IT.modified) BETWEEN 1 AND 30
It isn't completely clear to me what you mean by docType field.
Are you wanting a result like this?
Doctype:Link/User:120|Doc#:Link/Doctype:120|Created By:Link/User:120|Modified On:Date:120|
---------------------|---------------------|------------------------|--------------------|
Email Account |Jobs |Administrator | 2019-12-04 06:07:55|
Email Account |Notifications |Administrator | 2019-12-01 05:25:53|
Email Account |Replies |Administrator | 2019-12-01 05:25:53|
Email Account |Sales |Administrator | 2019-12-04 06:07:55|
Email Account |Support |Administrator | 2019-12-04 06:07:55|
Here's the select :
set #docType = "Email Account";
SELECT
#tabDocType AS `Doctype:Link/User:120`,
AD.name AS `Doc#:Link/Doctype:120`,
AD.owner AS `Created By:Link/User:120`,
AD.modified AS `Modified On:Date:120`
FROM `tabEmail Account` AS AD
Note the backticks on the field aliases! All these have different meanings in SQL:
"
'
`
The last one, backtick, is used to refer to database entities. You were trying to use “Doctype:Link/User:120” with double quotes, which declare plain text. Using backtick converts the alias into a db entity which can be referred to from elsewhere.
MariaDb doesn't allow the use of variables as table names directly, but you can do it using prepared statements, like this:
set #docType = "Email Account";
set #tabDocType = CONCAT('tab', #docType);
SET #sql_text = concat('
SELECT
"', #docType, '" AS `Doctype:Link/User:120`
, AD.name AS `Doc#:Link/Doctype:120`
, AD.owner AS `Created By:Link/User:120`
, AD.modified AS `Modified On:Date:120`
FROM `', #tabDocType, '` as AD;
');
PREPARE stmt FROM #sql_text;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
The table name is now also specified by a variable, created from concatenation of 'tab' with the docType declared before.
You get the same result as above but -- you avoid accidentally changing the table name in one place but not in the other when editing some time in the future.
to fetch doctype name you have to give the linked doctype name, For example,
select
IT.name as "IT No:Link/IT:120"

Find string in a large text with postgresql

I have a column called data in a PostgreSQL table that contains the following:
-----BEGIN HEADER-----
TYPE = PKCS#10
SERIAL = xxxxx
NOTBEFORE = Thu Sep 9 12:37:43 2010 UTC
LOA = 10
ROLE = xxxxx
RA = xxxxx
REQUEST_AUTH_USERID = CN=xxxxxxx
SCEP_TID = xxxxx
ARCHIVED_AFTER = Mon Nov 30 17:41:40 2015
_AFTER = Tue Jan 26 09:26:14 2016
-----END HEADER-----
-----BEGIN CERTIFICATE REQUEST-----
MIICWTCCAUECAQAwFjEUMBIGA1UEAwwLQ09QUzAwMDEzMDAwggEiMA0GCSqGSIb3
.
.
.
.
bV0eG4rlMOgTPv6mqb9HHKFqi3dsDzZKfXyoAsLOyOkj+AWXmAfXG8enT4uqBJJf
AsrUuJyTwzvmfdcEgYxokI6FU/nAjgQpmLkuVrE=
-----END CERTIFICATE REQUEST-----
As we want to move to a different application, I only need the part beginning with -----BEGIN CERTIFICATE REQUEST-----.
I tried to extract this string with substring and position in a SQL query but even if I try to find the possition of this string with:
SELECT position('-----BEGIN CERTIFICATE REQUEST-----' in (SELECT data from openca2.request where req_key = 3874))
I get a NULL value. I only can find examples where a part of a single string is extracted.
I don't know if the spaces are a problem. The part within the beginning and end header are not always the same.
Can this be done with a SQL query?
SELECT substr(
data,
position('-----BEGIN CERTIFICATE REQUEST-----' IN data)
)
FROM openca2.request
WHERE req_key = 3874;
How about:
SELECT split_part(data, '-----BEGIN CERTIFICATE REQUEST-----', 2)
FROM openca2.request
WHERE req_key = 3874;
If you want to keep '-----BEGIN CERTIFICATE REQUEST-----' then use '-----END HEADER-----' instead.
Thanks for your response. Both solutions are working.
I just have notices when I tried your queries that I was searching for the wrong req_key ..... and where I have the right req_key my solution works also
SELECT substring(data, position('-----BEGIN CERTIFICATE REQUEST-----' in (SELECT data from openca2.request where req_key = 3873)) +0 ,50000) from openca2.request where req_key = 3873
But yours look better as it is shorter :)
So this question is answered. THX again to you both.

Select Distinct with CASE - PostgreSQL

I am trying to select places infos from different tables: I have the place in one table, the geographical coordinates on another, and telephone and email in another. The issue is that we may or not have the email and telephone. I am looking for a way to get the email / phone when they exist, and have a blank value if they are not known. So I use the "CASE" instruction on the SELECT.
If we have no email and no phone, everything goes ok : we have only one line returned.
But if we have the email or the phone, it returns 2 lines; and the worst case is when we have both email and phones: in this case it returns three lines for each place :
place name , blank phone , blank mail
place name , blank phone , populated mail
place name , populated phone , blank mail
I am looking for a way to get only one line :
0) place name + populated (or not) phone + populated (or not) mail
I tried the 'distinct' but it doesn't do the trick :(
Here is my query :
select distinct
places.name as place,
CASE place_properties.pkey WHEN 'gen.telephone'
THEN place_properties.pvalue
END
as telephone,
CASE place_properties.pkey WHEN 'gen.email'
THEN place_properties.pvalue
END
as email
from
places
inner join
place_properties on place_properties.place_id = places.id
And here is a simplified answer example :
"ALLIAT" ;"0561059858" ;""
"ALLIAT" ;"" ;"contact#leslonguespistes.com"
"ALLIAT" ;"" ;""
"TARASCON SUR ARIEGE" ;"0561023281" ;""
"TARASCON SUR ARIEGE" ;"" ;"hotel#manoiragnes.com"
"TARASCON SUR ARIEGE" ;"" ;""
"Les Cabanes" ;"" ;""
We see that 'ALLIAT' and 'Tarascon' are returned three time because it has both a phone number and an email while "Les cabanes" is returned only once because it doesn't have any of it.
How to change the SQL to have only one line when we habe the email and/or the phone on the database?
try this:
SELECT
places.name AS place
, pp.telephone
, pp.email
FROM places
LEFT JOIN (
SELECT
place_id
, MAX(CASE place_properties.pkey WHEN 'gen.telephone' THEN place_properties.pvalue END) AS telephone
, MAX(CASE place_properties.pkey WHEN 'gen.email' THEN place_properties.pvalue END) AS email
FROM place_properties
WHERE place_properties.pkey IN ('gen.telephone', 'gen.email')
GROUP BY
place_id
) AS pp
ON places.id = pp.place_id
It might be possible to use alternatives to this approach but for that I would suggest we need to a good set of sample data.
It isn't clear if you only want places that have a phone of email, so I have used a LEFT JOIN which allows all places to be listed. If you do only want those places with (phone or email) then use an INNER JOIN instead
I think you can try this for get all email and telephone number
SELECT places.name AS place,
pp.telephone
pp.email
FROM places
LEFT JOIN (
SELECT
place_id,
ARRAY_TO_STRING(ARRAY_AGG(DISTINCT NULLIF(CASE place_properties.pkey WHEN 'gen.telephone' THEN place_properties.pvalue END,'')),',') AS telephone,
ARRAY_TO_STRING(ARRAY_AGG(DISTINCT NULLIF(CASE place_properties.pkey WHEN 'gen.email' THEN place_properties.pvalue END,'')),',') AS email
FROM place_properties
WHERE place_properties.pkey IN ('gen.telephone', 'gen.email')
GROUP BY 1
) AS pp
ON places.id = pp.place_id
You can use sub-selects here, like: select
name as place,
(select pvalue from place_properties where pkey = 'gen.telephone' and place_properties.place_id = places.id) as telephone,
(select pvalue from place_properties where pkey = 'gen.email' and place_properties.place_id = places.id) as email
from
places