Bash 更新存储在XML文件中的加密密码哈希以与域密码更改同步

Bash 更新存储在XML文件中的加密密码哈希以与域密码更改同步,bash,svn,maven,password-encryption,Bash,Svn,Maven,Password Encryption,有没有办法使settings.xml(Maven使用)与域密码更改保持同步?随着越来越多的开发迁移到maven,settings.xml中的repo列表也在增加,因此更新任务也在增加 我们最近开始在一些内部(公司)svn存储库中使用maven,这些存储库使用每个开发人员的域用户ID和密码来控制他们对存储库的访问。我们的域密码过期,必须经常更改。这意味着(经常)使用新密码哈希更新~/.m2/settings.xml 我更喜欢使用bash或csh解决方案,该解决方案使用我的系统上已经存在的简单命令

有没有办法使settings.xml(Maven使用)与域密码更改保持同步?随着越来越多的开发迁移到maven,settings.xml中的repo列表也在增加,因此更新任务也在增加

我们最近开始在一些内部(公司)svn存储库中使用maven,这些存储库使用每个开发人员的域用户ID和密码来控制他们对存储库的访问。我们的域密码过期,必须经常更改。这意味着(经常)使用新密码哈希更新~/.m2/settings.xml

我更喜欢使用bash或csh解决方案,该解决方案使用我的系统上已经存在的简单命令

我在这里看到了一些参考资料,所以看起来可能会有所帮助,我会向我们的CM员工推荐。但我并不乐观,它会很快被采纳,如果有的话。我没有时间维护另一个工具的私人副本

想法

谢谢,
Ken

我写了一个bash脚本,它可以正常工作。它需要在~/.m2/settings.xml中添加少量内容以获得支持(见下文)。该脚本采用一个可选参数:一个正则表达式字符串,用于匹配与xml文件中的一个或多个密码哈希关联的可选标记。我用它来表示域名,但它可以是任何东西(或者什么都不是,因为它是可选的)

该脚本提示输入要散列的新密码,它将新生成的散列限制为纯字母数字(以避免在其他地方出现意外外壳转义的潜在问题),它创建settings.xml文件的备份副本,然后更新settings.xml中选定的散列。以下是脚本:

#!/bin/bash
# Update instances of password-hashes in ~/.m2/settings.xml for a given password [and domain]
# Usage:  ./mvnpwd.sh  [domain-name-regex-string]

# Force domain-string to upper-case to keep things simple ...
mvnDomainNameRegexString=`echo $1 | tr '[a-z]' '[A-Z]'`

echo -n "New Password: "
read -s mvnPassword
echo

# Prefer pure alpha-numeric hash ...
mvnPasswordHash=""
while [ -z "$mvnPasswordHash" ]
do
    mvnHashMash=`mvn --encrypt-password "$mvnPassword"`
    mvnPasswordHash=`echo "$mvnHashMash" | egrep -o "\{[[:alnum:]]+\=\}"`
done

cp ~/.m2/settings.xml ~/.m2/settings.xml.old

oldPasswordHash=`egrep -o "<changingPasswordHash_*$mvnDomainNameRegexString>\{[a-zA-Z0-9]+\=\}</changingPasswordHash_*$mvnDomainNameRegexString>" ~/.m2/settings.xml | egrep -o "\{[a-zA-Z0-9]+\=\}"`
set $oldPasswordHash
for p do
    sed --in-place -e "s/$p/$mvnPasswordHash/g" ~/.m2/settings.xml
done
#/bin/bash
#更新~/.m2/settings.xml中给定密码[和域]的密码哈希实例
#用法:./mvnpwd.sh[域名正则表达式字符串]
#强制域字符串为大写以保持简单。。。
mvnDomainNameRegexString=`echo$1 | tr'[a-z]''[a-z]'`
echo-n“新密码:”
read-s mvnPassword
回声
#更喜欢纯字母数字哈希。。。
mvnPasswordHash=“”
而[-z“$mvnPasswordHash”]
做
mvnHashMash=`mvn--加密密码“$mvnPassword”`
mvnPasswordHash=`echo“$mvnHashMash”| egrep-o“\{[[:alnum:]+\=\}”`
完成
cp~/.m2/settings.xml~/.m2/settings.xml.old
oldPasswordHash=`egrep-o“\{[a-zA-Z0-9]+\=\}”~/.m2/settings.xml | egrep-o“\{[a-zA-Z0-9]+\=\}”`
设置$oldPasswordHash
对于p do
sed--就地-e“s/$p/$mvnPasswordHash/g”~/.m2/settings.xml
完成
我在settings.xml文件顶部附近添加了一个注释块来支持我的脚本。我使用类似xml的标记来标识(对于脚本)xml文件中其他地方使用的密码散列值,并将任何[可选]域名与给定的散列值相关联。因为所有这些都发生在注释块中,所以maven应该忽略它。下面是settings.xml示例:

<settings>
    <!--  Info below is to aid in updating passwords that change periodically (e.g., domain password) ...
    <changingPasswordHash>{SomeHashWithoutADomainxYzZyHaShGiBbErIsHsTuFf=}</changingPasswordHash>
    <changingPasswordHash_MYDOMAIN>{SomeHashForMyDomainxYzZyHaShGiBbErIsHsTuFf=}</changingPasswordHash_MYDOMAIN>
    <changingPasswordHash_ANOTHERDOMAIN>{SomeHashForAnotherDomainxYzZyHaShGiBbErIsHsTuFf=}</changingPasswordHash_ANOTHERDOMAIN>
    -->
    <proxies>
        <proxy>
            <active>true</active>
            <protocol>http</protocol>
            <host>myProxy.rightHere.com</host>
            <port>80</port>
            <username>justMe</username>
            <password>{SomeHashWithoutADomainxYzZyHaShGiBbErIsHsTuFf=}</password>
            <nonProxyHosts>*.rightHere.com|*.whereIWork.com</nonProxyHosts>
        </proxy>
    </proxies>
    <servers>
        <server>
            <id>mySVNrepo1.rightHere.com</id>
            <username>justMe</username>
            <password>{SomeHashForMyDomainxYzZyHaShGiBbErIsHsTuFf=}</password>
        </server>
        <server>
            <id>corpSVNrepo2.whereIWork.com</id>
            <username>justMe</username>
            <password>{SomeHashForAnotherDomainxYzZyHaShGiBbErIsHsTuFf=}</password>
        </server>
        <server>
            <id>anotherSVNrepo3.notHere.com</id>
            <username>myOtherUserID</username>
            <password>{SomeHashWithoutADomainxYzZyHaShGiBbErIsHsTuFf=}</password>
        </server>
    </servers>
</settings>

真的
http
myProxy.righthhere.com
80
只是我
{somehashwithoutadomainxyzyhashgibberishstuff=}
*.rightshere.com |*.whereIWork.com
mysvrepo1.righthhere.com
只是我
{somehashformydomainxyzyhashgibberishstuff=}
corpsvrepo2.whereIWork.com
只是我
{somehashforotherdomainxyzyhashgibberishstuff=}
另一个svnrepo3.notHere.com
myOtherUserID
{somehashwithoutadomainxyzyhashgibberishstuff=}